{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/9671","repository_url":"https://api.github.com/repos/nodejs/node","labels_url":"https://api.github.com/repos/nodejs/node/issues/9671/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/9671/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/9671/events","html_url":"https://github.com/nodejs/node/issues/9671","id":190262220,"number":9671,"title":"readFile() and readFileSync() fail to read sparse file on Windows","user":{"login":"jorangreef","id":413206,"avatar_url":"https://avatars.githubusercontent.com/u/413206?v=3","gravatar_id":"","url":"https://api.github.com/users/jorangreef","html_url":"https://github.com/jorangreef","followers_url":"https://api.github.com/users/jorangreef/followers","following_url":"https://api.github.com/users/jorangreef/following{/other_user}","gists_url":"https://api.github.com/users/jorangreef/gists{/gist_id}","starred_url":"https://api.github.com/users/jorangreef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jorangreef/subscriptions","organizations_url":"https://api.github.com/users/jorangreef/orgs","repos_url":"https://api.github.com/users/jorangreef/repos","events_url":"https://api.github.com/users/jorangreef/events{/privacy}","received_events_url":"https://api.github.com/users/jorangreef/received_events","type":"User","site_admin":false},"labels":[{"id":155435785,"url":"https://api.github.com/repos/nodejs/node/labels/fs","name":"fs","color":"0052cc","default":false},{"id":166236401,"url":"https://api.github.com/repos/nodejs/node/labels/windows","name":"windows","color":"9944dd","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-11-18T08:29:35Z","updated_at":"2016-11-18T15:06:21Z","closed_at":null,"body":"* **Version**: v7.1.0\r\n* **Platform**: Windows 10 64-bit\r\n* **Subsystem**: fs\r\n\r\nI wrote a small test that passes on Mac and Linux but throws on Windows:\r\n\r\n```\r\nvar fs = require('fs');\r\nvar buffer = Buffer.alloc(8192);\r\nvar path = 'test-sparse-read-file';\r\nvar fd = fs.openSync(path, 'w+');\r\nconsole.log('created or truncated, sparse file size is now: ' + fs.fstatSync(fd).size);\r\n\r\nconsole.log('writing 1 byte at offset ' + (8192 - 1));\r\nfs.writeSync(fd, Buffer.alloc(1, 1), 0, 1, 8192 - 1);\r\nconsole.log('sparse file size is now: ' + fs.fstatSync(fd).size + '\\r\\n');\r\n\r\nconsole.log('reading 8192 bytes using readSync()...');\r\nvar bytesRead = fs.readSync(fd, buffer, 0, 8192, 0);\r\nif (bytesRead !== 8192) {\r\n  throw new Error('readSync() read ' + bytesRead + ' bytes');\r\n} else {\r\n  console.log('readSync() read ' + bytesRead + ' bytes');\r\n}\r\n\r\nconsole.log('\\r\\nreading entire file using readFileSync()...');\r\nvar result = fs.readFileSync(fd);\r\nif (result.length !== buffer.length) {\r\n  throw new Error('readFileSync returned a buffer with length ' + result.length);\r\n} else {\r\n  console.log('readFileSync returned a buffer with length ' + result.length);\r\n}\r\n\r\nfs.closeSync(fd);\r\nfs.unlinkSync(path);\r\nconsole.log('\\r\\nPASSED');\r\n```\r\n\r\nLinux:\r\n```\r\ncreated or truncated, sparse file size is now: 0\r\nwriting 1 byte at offset 8191\r\nsparse file size is now: 8192\r\n\r\nreading 8192 bytes using readSync()...\r\nreadSync() read 8192 bytes\r\n\r\nreading entire file using readFileSync()...\r\nreadFileSync returned a buffer with length 8192\r\n\r\nPASSED\r\n```\r\n\r\nWindows:\r\n```\r\ncreated or truncated, sparse file size is now: 0\r\nwriting 1 byte at offset 8191\r\nsparse file size is now: 8192\r\n\r\nreading 8192 bytes using readSync()...\r\nreadSync() read 8192 bytes\r\n\r\nreading entire file using readFileSync()...\r\nC:\\Users\\Joran\\test-sparse.js:22\r\n  throw new Error('readFileSync returned a buffer with length ' + result.length);\r\n  ^\r\n\r\nError: readFileSync returned a buffer with length 0\r\n    at Object.<anonymous> (C:\\Users\\Joran\\test-sparse.js:22:9)\r\n    at Module._compile (module.js:573:32)\r\n    at Object.Module._extensions..js (module.js:582:10)\r\n    at Module.load (module.js:490:32)\r\n    at tryModuleLoad (module.js:449:12)\r\n    at Function.Module._load (module.js:441:3)\r\n    at Module.runMain (module.js:607:10)\r\n    at run (bootstrap_node.js:420:7)\r\n    at startup (bootstrap_node.js:139:9)\r\n    at bootstrap_node.js:535:3\r\n```\r\n\r\nThe test shows that the problem does not appear to be with read() but only with readFileSync().\r\n\r\nreadFile() has the same issue.\r\n"},"comment":{"url":"https://api.github.com/repos/nodejs/node/issues/comments/261553487","html_url":"https://github.com/nodejs/node/issues/9671#issuecomment-261553487","issue_url":"https://api.github.com/repos/nodejs/node/issues/9671","id":261553487,"user":{"login":"sam-github","id":17607,"avatar_url":"https://avatars.githubusercontent.com/u/17607?v=3","gravatar_id":"","url":"https://api.github.com/users/sam-github","html_url":"https://github.com/sam-github","followers_url":"https://api.github.com/users/sam-github/followers","following_url":"https://api.github.com/users/sam-github/following{/other_user}","gists_url":"https://api.github.com/users/sam-github/gists{/gist_id}","starred_url":"https://api.github.com/users/sam-github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sam-github/subscriptions","organizations_url":"https://api.github.com/users/sam-github/orgs","repos_url":"https://api.github.com/users/sam-github/repos","events_url":"https://api.github.com/users/sam-github/events{/privacy}","received_events_url":"https://api.github.com/users/sam-github/received_events","type":"User","site_admin":false},"created_at":"2016-11-18T15:06:21Z","updated_at":"2016-11-18T15:06:21Z","body":"Does not throw on unixen, as expected.\r\n\r\nPlease remove the complex ball of js code that is `readFile*` from the picture, and replace that last line with `assert.equal(filleLength, fs.readSync(fd, buf, 0, 10, 0)`, which I strongly suspect will not pass on Windows.\r\n"}}
{"actor":{"display_login":"sam-github"}}