Last active
August 29, 2015 14:13
-
-
Save kuryaki/bf10b43039c3c0a6b454 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var object = {"hola":"mundo", "data":""} | |
| var objectBuffer = new Buffer(JSON.stringify(object)) | |
| console.log(objectBuffer.length) // this should be 26 OK | |
| var data0 = new Buffer('normal', 'utf-8') | |
| console.log(data0.length) // this should be 6 OK | |
| var data1 = new Buffer('"normal', 'utf-8') // Note extra double quote (it only happends with double quotes weird characters like ó work ok) | |
| console.log(data1.length) // this should be 7 OK | |
| object.data = data0.toString('utf-8', 0, 4) | |
| console.log(object) // {hola:'mundo', data:'norm'} OK | |
| var objectBuffer = new Buffer(JSON.stringify(object)) | |
| console.log(objectBuffer.length) // this should be 30 OK | |
| object.data = data1.toString('utf-8', 0, 4) | |
| console.log(object) // {hola:'mundo', data:'"norm'} OK | |
| var objectBuffer = new Buffer(JSON.stringify(object)) | |
| console.log(objectBuffer.length) // this should be 30 NOT OK got 31 instead |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment