
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
buffered-file-reader
Advanced tools
A promise-based buffered reader for sequential byte-wise binary file input.
NPM package: buffered-file-reader
Examples of how to use it: github.com/chdh/buffered-file-reader/tree/main/examples
"Locate mode" is used to access data within the internal data buffer.
Locate mode is a very old concept which was was common in IBM mainframes with PL/I. It's used to avoid copying file data and to allow fast byte-wise inspection of the data stream.
With the "view" functionality of the Node.js Buffer and JavaScript TypedArray classes, it's now possible to use this concept in a modern programming environment.
static Reader.open(fileName: string, options?: OpenOptions) : Promise<Reader>
Opens a file and returns a Reader object.
fileName
: The name of a file to read from.options
: Optional options (see below).interface OpenOptions {
bufferSize?: number; // size of the internal data buffer, default is to use 256 KB
preallocatedBuffer?: Buffer; // a pre-allocated buffer to be re-used instead of using bufferSize to allocate a new buffer
}
reader.close() : Promise<void>
Closes the Reader object and the underlying file handle.
reader.get(length: number) : Promise<Buffer|undefined>
Returns a view into the internal data buffer at the current file position.
length
:
Specifies the number of bytes requested.length
should be much smaller than the size of the internal data buffer.undefined
is returned.The current file position is not advanced.
reader.advance(length: number)
Advances the current file position.
reader.filePosition : number
Returns the current file position.
import {Reader} from "buffered-file-reader";
const reader = await Reader.open("test.txt");
let buf = await reader.get(4);
console.log("First 4 bytes: ", buf.subarray(0, 4));
console.log("Available bytes in the buffer view: ", buf.length);
reader.advance(100);
buf = await reader.get(1);
console.log("Byte at position 100: ", buf[0]);
await reader.close();
FAQs
A promise-based buffered file reader.
We found that buffered-file-reader 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.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.