Thursday 29 June 2017

Is there an equivalent of getc?

I'm writing a program that's based on a C script, and part of that involves reading (or writing) a file byte-by-byte at different parts of the script.Writing seems simple enough to recreatevar newFile = fs.createWriteStream("createdThingy.txt"); for(var i = 0; i < 256; i++) { newFile.write(Buffer.from([Math.floor(Math.random() * 256)])); } Reading byte-by-byte, on the other hand, is a bit muddier. I was hoping I could do something likevar newFile = fs.openSync("navyseal.txt","r"); var firstThingy = fs.readSync(newFile); var nextThingy = fs.readSync(newFile); for(var i = 0; i < firstThingy; i++) { var anotherByte = fs.readSync(newFile); console.log(anotherByte); } But that doesn't work at all, and despite looking over the docs on fs, I have no idea what I'm doing

Submitted June 29, 2017 at 08:27AM by DoomTay

No comments:

Post a Comment