Wrong fs.stat size on win32 #1647

fprijate opened this Issue Sep 4, 2011 · 7 comments


None yet

5 participants


platform win32, MSVC build

fs.stat and fs.statSync return wrong size

Node.js Foundation member

We may be mixing up struct _stat and struct _stat64.


Yes with this change size is correct (on XP)
On win7 probably _wstat64 ?

diff D:/INSTALL/AJAX/node/src/node.h D:/INSTALL/AJAX/node1/src/node.h
< # define NODE_STAT _stati64
< # define NODE_FSTAT _fstati64
< # define NODE_STAT_STRUCT struct _stati64
> # define NODE_STAT _stat
> # define NODE_FSTAT _fstat
> # define NODE_STAT_STRUCT struct _stat

Node.js Foundation member

This bug should be closed after the next libuv update.


Looks fixed to me. (msvc build @8153a21, xp sp3)

var assert = require('assert');
var fs = require('fs');

var data = Buffer("Some data to test writing and stating afterwards");

// sync
var fd = fs.openSync('test.txt', 'w');
fs.writeSync(fd, data, 0, data.length, 0);

var s = fs.statSync('test.txt');
assert.equal(s.size+1, data.length);

// async
fs.open('test.txt', 'w', function(err, fd) {
  fs.write(fd, data, 0, data.length, 0, function(err, w, buf) {
    if(w == data.length) {
      fs.stat('test.txt', function (err, stats) {
        assert.equal(stats.size, data.length);
Node.js Foundation member

@cryptix: why the s.size+1? Your test fails for me here (linux, latest master) as I suppose it should.


Oh no.. thats awkward.. i'm sorry.
Of Course it fails for me, too. I wanted to see if the assertion triggers if the size would be off and copyd without paying attention.
Without the +1 the test should be fine i think.. ~_~

@fprijate fprijate closed this Sep 7, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment