{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/18921","repository_url":"https://api.github.com/repos/nodejs/node","labels_url":"https://api.github.com/repos/nodejs/node/issues/18921/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/18921/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/18921/events","html_url":"https://github.com/nodejs/node/issues/18921","id":299132257,"number":18921,"title":"Same Buffer but different output","user":{"login":"BubuAnabelas","id":14363444,"avatar_url":"https://avatars2.githubusercontent.com/u/14363444?v=4","gravatar_id":"","url":"https://api.github.com/users/BubuAnabelas","html_url":"https://github.com/BubuAnabelas","followers_url":"https://api.github.com/users/BubuAnabelas/followers","following_url":"https://api.github.com/users/BubuAnabelas/following{/other_user}","gists_url":"https://api.github.com/users/BubuAnabelas/gists{/gist_id}","starred_url":"https://api.github.com/users/BubuAnabelas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BubuAnabelas/subscriptions","organizations_url":"https://api.github.com/users/BubuAnabelas/orgs","repos_url":"https://api.github.com/users/BubuAnabelas/repos","events_url":"https://api.github.com/users/BubuAnabelas/events{/privacy}","received_events_url":"https://api.github.com/users/BubuAnabelas/received_events","type":"User","site_admin":false},"labels":[{"id":151728679,"url":"https://api.github.com/repos/nodejs/node/labels/question","name":"question","color":"cc317c","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-02-21T21:18:38Z","updated_at":"2018-02-21T21:47:34Z","closed_at":null,"author_association":"NONE","body":"<!--\r\nThank you for reporting an issue.\r\n\r\nThis issue tracker is for bugs and issues found within Node.js core.\r\nIf you require more general support please file an issue on our help\r\nrepo. https://github.com/nodejs/help\r\n\r\n\r\nPlease fill in as much of the template below as you're able.\r\n\r\nVersion: output of `node -v`\r\nPlatform: output of `uname -a` (UNIX), or version and 32 or 64-bit (Windows)\r\nSubsystem: if known, please specify affected core module name\r\n\r\nIf possible, please provide code that demonstrates the problem, keeping it as\r\nsimple and free of external dependencies as you are able.\r\n-->\r\n\r\n* **Version**: v9.4.0\r\n* **Platform**: `Linux 3.2.14-cmpc-rc7 #2 SMP Fri May 4 14:20:59 CST 2012 i686 i686 i686 GNU/Linux`\r\n* **Subsystem**: Mint 13 Maya\r\n\r\n<!-- Enter your issue details below this comment. -->\r\n\r\nI was using the `chalk` library for colorizing the output but when I tried to pass it through a unix pipe the control characters where gone.\r\n```javascript\r\nconst chalk = require('chalk')\r\nconst text = chalk.red`Hello World`\r\nconsole.log(text)\r\n```\r\nWhen I run it and pass it to xxd like this `node colors.js | xxd` i get:\r\n`0000000: 4865 6c6c 6f20 576f 726c 640a            Hello World.`\r\n\r\nSo I decided to see the bytes behind chalk's output with a Buffer and make the colored text by hand.\r\n```javascript\r\nconst bufferText = Buffer.from(text) // <Buffer 1b 5b 33 31 6d 48 65 6c 6c 6f 20 57 6f 72 6c 64 1b 5b 33 39 6d>\r\n\r\nconst coloredText = '\\x1b[31mHello World\\x1b[39m'\r\nconsole.log(coloredText === text) // true\r\n```\r\nBut here's where the magic occurs, if I only do `console.log(coloredText)` and pass it through the pipe again like `node colors.js | xxd` I get:\r\n```\r\n0000000: 1b5b 3331 6d48 656c 6c6f 2057 6f72 6c64  .[31mHello World\r\n0000010: 1b5b 3339 6d0a                           .[39m.\r\n```\r\n\r\nI kept going to see if the bytes where the same, so I made a Buffer from coloredText and checked if it was equal to bufferText\r\n```javascript\r\nconst bufferColored = Buffer.from(coloredText) // <Buffer 1b 5b 33 31 6d 48 65 6c 6c 6f 20 57 6f 72 6c 64 1b 5b 33 39 6d>\r\nconsole.log(bufferColored.equals(bufferText)) // true\r\n```\r\n\r\nI continued looking for something to explain why the same bytes acted differently on the output, I logged both buffers with the toString() method and the output was different too.\r\nAs far as I understand the same binary data should give the same output that's why I'm reporting this as an issue.\r\nI might be wrong and hope you can enlighten me in that case."},"comment":{"url":"https://api.github.com/repos/nodejs/node/issues/comments/367485034","html_url":"https://github.com/nodejs/node/issues/18921#issuecomment-367485034","issue_url":"https://api.github.com/repos/nodejs/node/issues/18921","id":367485034,"user":{"login":"BubuAnabelas","id":14363444,"avatar_url":"https://avatars2.githubusercontent.com/u/14363444?v=4","gravatar_id":"","url":"https://api.github.com/users/BubuAnabelas","html_url":"https://github.com/BubuAnabelas","followers_url":"https://api.github.com/users/BubuAnabelas/followers","following_url":"https://api.github.com/users/BubuAnabelas/following{/other_user}","gists_url":"https://api.github.com/users/BubuAnabelas/gists{/gist_id}","starred_url":"https://api.github.com/users/BubuAnabelas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BubuAnabelas/subscriptions","organizations_url":"https://api.github.com/users/BubuAnabelas/orgs","repos_url":"https://api.github.com/users/BubuAnabelas/repos","events_url":"https://api.github.com/users/BubuAnabelas/events{/privacy}","received_events_url":"https://api.github.com/users/BubuAnabelas/received_events","type":"User","site_admin":false},"created_at":"2018-02-21T21:47:34Z","updated_at":"2018-02-21T21:47:34Z","author_association":"NONE","body":"@addaleax It only makes sense partially, because once I have the Buffer isn't all just raw bytes?\r\nWhen I do `console.log(bufferText.toString())` shouldn't `node` convert those raw bytes to ascii or unicode and write it to `stdout`?\r\nThere's where I see the problem, or where I don't understand Buffers behavior."}}
{"actor":{"display_login":"BubuAnabelas"}}