Getting ready

We'll need a file to read.

We can use the following to populate a file with 1 MB of data:

$ node -p "Buffer.allocUnsafe(1e6).toString()" > file.dat
Allocating buffers
When the Buffer constructor is passed a number, the specified amount of bytes will be allocated from deallocated memory, data in RAM that was previously discarded. This means the buffer could contain anything. From Node 6 and above, passing a number to Buffer is deprecated. Instead, we use Buffer.allocUnsafe to achieve the same effect, or just Buffer.alloc to have a zero-filled buffer (but at the cost of slower instantiation). To state the obvious, the file we generated for ourselves (file.dat) should not be shared with anyone else.

We'll also want to create a source file; let's call it null-byte-remover.js.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.194.170