Skip to content

Latest commit

 

History

History
19 lines (15 loc) · 387 Bytes

read-file.md

File metadata and controls

19 lines (15 loc) · 387 Bytes

Read from a file

require('libsys/shim');
const libjs = require('libjs');

const O_RDONLY = 0;
const fd = libjs.open(__filename, O_RDONLY);

if(fd > -1) {
    const buf = new Buffer(1024);
    const bytes_read = libjs.read(fd, buf);

    console.log('Bytes read: ', bytes_read);
    console.log(buf.toString().substr(0, bytes_read));
} else {
    console.log('Error: ', fd);
}