Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
bufferfromfile
Advanced tools
Module in JavaScript providing convenient means for using files as standard ArrayBuffer making mmap behind the scene.
Module in JavaScript providing convenient means for using files as standard ArrayBuffer making mmap behind the scene. BufferFromFile uses mmap to map file from hard drive to memory returning ArrayBuffer or TypedBuffer which can be manipulated just like ordinary buffer. mmap() creates a new mapping in the virtual address space of the calling process. During mmap operation all performance issues addressed operation system, so it's nearly fastest way to get data from / store on hard drive in Java Script. This method of data access do zero copy, unlike others. Just like native version of the routine BufferFromFile accept ( protection ), ( flags ), ( offset ), ( size ) and even ( advise ) parameters each of which has default value so no need to pass the implicitly.
BufferFromFIle works on Windows, OSX, Linux and other Unix-like systems. The module doesn't depend of module nan and does not support deprecated versions of Nodejs. The module can convert a file to standard ArrayBuffer or any kind of TypedBuffer or even deprecated Nodejs Buffer.
var buffer = BufferFromFile( filePath ).Uint8Array();
// edit single byte
buffer[ 0 ] = 48 + Math.round( Math.random()*9 );
// print the buffer
console.log( 'buffer.length :',buffer.length );
console.log( 'buffer.toString :',buffer.toString() );
// unmap file
BufferFromFile.unmap( buffer );
// mmap file
var filePath = __dirname + '/TestFile.txt';
var buffer = BufferFromFile({ filePath : filePath, protection : BufferFromFile.Protection.read }).Uint8Array();
// attempt to write data would give error
/* buffer[ 0 ] = 48 + Math.round( Math.random()*9 ); */
// read data and status
console.log( 'buffer.toString :',buffer.toString() );
console.log( 'status',BufferFromFile.status( buffer ) );
// unmap file
BufferFromFile.unmap( buffer );
// mmap file
var buffer = BufferFromFile( filePath ).Uint8Array();
// write data
buffer[ 0 ] = 48 + Math.round( Math.random()*9 );
// flush written data to make sure data on will get on hard drive shortly
BufferFromFile.flush( buffer );
// rewrite data
buffer[ 0 ] = 48 + Math.round( Math.random()*9 );
// unmap file
BufferFromFile.unmap( buffer );
FAQs
The module in JavaScript provides convenient means for using files as standard ArrayBuffer making mmap behind the scene.
The npm package bufferfromfile receives a total of 15 weekly downloads. As such, bufferfromfile popularity was classified as not popular.
We found that bufferfromfile demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.