{"action":"created","issue":{"url":"https://api.github.com/repos/substack/node-browserify/issues/1545","repository_url":"https://api.github.com/repos/substack/node-browserify","labels_url":"https://api.github.com/repos/substack/node-browserify/issues/1545/labels{/name}","comments_url":"https://api.github.com/repos/substack/node-browserify/issues/1545/comments","events_url":"https://api.github.com/repos/substack/node-browserify/issues/1545/events","html_url":"https://github.com/substack/node-browserify/issues/1545","id":148306725,"number":1545,"title":"Transform buffer chunk weirdness","user":{"login":"asbjornenge","id":241601,"avatar_url":"https://avatars.githubusercontent.com/u/241601?v=3","gravatar_id":"","url":"https://api.github.com/users/asbjornenge","html_url":"https://github.com/asbjornenge","followers_url":"https://api.github.com/users/asbjornenge/followers","following_url":"https://api.github.com/users/asbjornenge/following{/other_user}","gists_url":"https://api.github.com/users/asbjornenge/gists{/gist_id}","starred_url":"https://api.github.com/users/asbjornenge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asbjornenge/subscriptions","organizations_url":"https://api.github.com/users/asbjornenge/orgs","repos_url":"https://api.github.com/users/asbjornenge/repos","events_url":"https://api.github.com/users/asbjornenge/events{/privacy}","received_events_url":"https://api.github.com/users/asbjornenge/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-04-14T09:44:01Z","updated_at":"2016-04-14T23:16:51Z","closed_at":null,"body":"So I have this simple transform here:\r\n\r\n```js\r\nvar mime = require('mime')\r\nvar through = require('through2')\r\nvar isImg = function(file) { return (/\\.((lit)?gif|png|jpg|jpeg|svg)$/).exec(file) }\r\n\r\nmodule.exports = function(file) {\r\n  if (!isImg(file)) return through()\r\n  var type = mime.lookup(file)\r\n  var enc  = type == 'image/svg+xml' ? 'utf-8' : 'base64'\r\n  var meta = type == 'image/svg+xml' ? ';charset=utf8,' : ';base64,'\r\n  var buffers = []\r\n  return through(\r\n    function(buf, enc, cb) {\r\n      buffers.push(buf)\r\n      cb()\r\n    },\r\n    function(end) {\r\n      var data = Buffer.concat(buffers).toString(enc)\r\n      var mod = \"module.exports = 'data:\"+type+meta+data+\"'\"\r\n      this.push(mod)\r\n      end()\r\n    }\r\n  )\r\n}\r\n```\r\n\r\nFor some reason, from browserify `12.0.0` and up this started producing wrong `base64` strings. If I read the file using `fs` - and ignore the buffers passed by browserify - everything is fine.\r\n\r\n```js\r\nmodule.exports = function(file) {\r\n  if (!isImg(file)) return through()\r\n  var type = mime.lookup(file)\r\n  var enc  = type == 'image/svg+xml' ? 'utf-8' : 'base64'\r\n  var meta = type == 'image/svg+xml' ? ';charset=utf8,' : ';base64,'\r\n  var data = fs.readFileSync(file).toString(enc)\r\n  return through(\r\n    function(buf, enc, cb) { cb() },\r\n    function(end) {\r\n      var mod = \"module.exports = 'data:\"+type+meta+data+\"'\"\r\n      this.push(mod)\r\n      end()\r\n    }\r\n  )\r\n}\r\n```\r\n\r\n^ But that is not so great since I'm slowing down bundling by using `readFileSync` here, right? Also, looking at the `buf.length` using browserify 11 and 12 produce completely different buffer sizes!?\r\n\r\nAnyone have any idea what might be wrong? Any help would be greatly appreciated :smile: \r\n\r\n```\r\n$ ls -la node_modules\r\nlrwxrwxrwx   1 asbjorn asbjorn    26 Apr 14 10:58 browserify -> .store/browserify@13.0.0/_/\r\nlrwxrwxrwx   1 asbjorn asbjorn    19 Apr 14 10:58 mime -> .store/mime@1.3.4/_/\r\nlrwxrwxrwx   1 asbjorn asbjorn    23 Apr 14 10:58 mochify -> .store/mochify@2.17.0/_/\r\nlrwxrwxrwx   1 asbjorn asbjorn    23 Apr 14 10:58 through2 -> .store/through2@2.0.1/_/\r\n```"},"comment":{"url":"https://api.github.com/repos/substack/node-browserify/issues/comments/210200009","html_url":"https://github.com/substack/node-browserify/issues/1545#issuecomment-210200009","issue_url":"https://api.github.com/repos/substack/node-browserify/issues/1545","id":210200009,"user":{"login":"mderijcke","id":1220691,"avatar_url":"https://avatars.githubusercontent.com/u/1220691?v=3","gravatar_id":"","url":"https://api.github.com/users/mderijcke","html_url":"https://github.com/mderijcke","followers_url":"https://api.github.com/users/mderijcke/followers","following_url":"https://api.github.com/users/mderijcke/following{/other_user}","gists_url":"https://api.github.com/users/mderijcke/gists{/gist_id}","starred_url":"https://api.github.com/users/mderijcke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mderijcke/subscriptions","organizations_url":"https://api.github.com/users/mderijcke/orgs","repos_url":"https://api.github.com/users/mderijcke/repos","events_url":"https://api.github.com/users/mderijcke/events{/privacy}","received_events_url":"https://api.github.com/users/mderijcke/received_events","type":"User","site_admin":false},"created_at":"2016-04-14T23:16:51Z","updated_at":"2016-04-14T23:16:51Z","body":"My first guess is newline conversions being changed or utf8 / unicode related.\r\n\r\nYou should grab the base64 strings, decode both of them and look at the differences. As it's XML you can use any generic diff tool."}}