nodejs / node-v0.x-archive

Moved to https://github.com/nodejs/node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fs.readFileSync returning abnormal behavior

backcopy opened this issue · comments

app.js

'use strict'; 

var fs = require('fs'); 

let grab_data_function = function(fileName) {
    let partial_file_prior = fs.readFileSync(`${fileName}`,'utf8');  
            let temp_database = []; 
        temp_database.push(partial_file_prior); 
    return temp_database;   
}; 


let example = grab_data_function('journal.txt'); 

console.log(example);  

journal.txt (in root directory, same as app.js)

1000;JAN-16;100000;0;
3000;JAN-16;0;100000;
7140;JAN-16;36000;0;
1000;JAN-16;0;36000;
1100;FEB-16;80000;0;
1000;FEB-16;0;60000;
2000;FEB-16;0;20000;
1110;FEB-16;17600;0;
2010;FEB-16;0;17600;
1000;MAR-16;28500;0;
4000;MAR-16;0;28500;
2010;MAR-16;17600;0;
1000;MAR-16;0;17600;
5000;APR-16;19100;0;
1000;APR-16;0;19100;
1000;APR-16;32900;0;
1020;APR-16;21200;0;
4000;APR-16;0;54100;
1000;MAY-16;15300;0;
1020;MAY-16;0;15300;
1000;MAY-16;4000;0;
4090;MAY-16;0;4000;
1110;JUN-16;5200;0;
2010;JUN-16;0;5200;
5100;JUN-16;19100;0;
1000;JUN-16;0;19100;
4120;JUN-16;5000;0;
1000;JUN-16;0;5000;
7160;JUL-16;2470;0;
2010;JUL-16;0;2470;
5500;JUL-16;3470;0;
1000;JUL-16;0;3470;

This will return the array [ '' ]

  1. When doing console.log(typeof partial_file_prior) it will return 'string' but when trying to access partial_file_prior it returns an empty buffer(?)

I'm using node version 4.7.3 via the cloud9 (c9.io platform)

@edinjusupovic This is an arhive repository. Could you open the issue in the https://github.com/nodejs/node ?

BTW, I can't reproduce with 4.7.3 om Windows 7. What output does console.log(partial_file_prior) give?

Could it be that you launch app.js from a directory that has its own empty journal.txt ?

@edinjusupovic as @vsemozhetbyt has just noted, please file this issue in the main Node.js repo issue tracker. This is an archive repository for the codebase of Node.js 0.12 and older. Thanks!

@vsemozhetbyt can confirm the issue was with my side, it appears c9.io had some sort of error and the file wasn't actually properly being written to the disk despite providing confirmation it was written. Nonetheless, fixed now.

@edinjusupovic Thank you for the info.