Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var fs = require('fs');
var CHUNK_SIZE = 4 * 1024;
var buffer = new Buffer(CHUNK_SIZE);
var filePath = __dirname + '/public/index.html';
// fs.open(filePath, 'r', function(err, fd) {
// if (err) throw err;
//
// fs.read(fd, buffer, 0, CHUNK_SIZE, null, function(err, nread) {
// if (err) throw err;
//
// console.log(buffer.slice(0, nread).toString('utf8'));
//
// fs.close(fd, function(err) {
// if (err) throw err;
// });
// });
// });
var fd = fs.openSync(filePath, 'r');
var nread = fs.readSync(fd, buffer, 0, CHUNK_SIZE, null);
console.log(buffer.slice(0, nread).toString('utf8'));
fs.closeSync(fd);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.