joyent/node — Issue #2807: readSync() breaks on Windows
Author: arturadib
Created: 2012-02-22 19:44:38+00:00
State: open

Using Node v0.6.11, Windows 7.

When a `position` larger than the file size is specified `readSync()` breaks on Windows, whereas on OS X it simply returns `0`.

Here's a reduction:

```javascript
var fs = require('fs');

fs.writeFileSync('file.txt', 'hello world', 'utf8');

var BUF_LENGTH = 1024,
fd = fs.openSync('file.txt', 'r'),
buf = new Buffer(BUF_LENGTH),
pos = 0;

pos += fs.readSync(fd, buf, 0, BUF_LENGTH, pos); // OK because pos < file size
pos += fs.readSync(fd, buf, 0, BUF_LENGTH, pos); // breaks on Windows

console.log(pos); // should be '11'
```

Here's the exception thrown:

```
Error: UNKNOWN, unknown error
at Object.readSync (fs.js:273:19)
at Object. (Z:\temp\t\readSync.js:12:11)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
at EventEmitter._tickCallback (node.js:192:40)
```