Skip to content

Instantly share code, notes, and snippets.

@alessioalex
Created April 7, 2016 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alessioalex/474c05b31ba635a5938112a1efb5e7ef to your computer and use it in GitHub Desktop.
Save alessioalex/474c05b31ba635a5938112a1efb5e7ef to your computer and use it in GitHub Desktop.
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