
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
file-cursor
Advanced tools
Node.js has a nice FS implementation in place. But there are no simple methods to open a file cursor and jump forward or backward through bytes easily (as far as I know). This library should be an optimized way to handle gigantic files and hops back and forth between bytes without too many problems.
The goal is to read a sequence of bytes from a file's random place without allocating everything in memory.
Node.js uses native code to do that, but It needs to be used from the JavaScript side (our side). This transition will add some wait time to the execution. To be more efficient, components like FS streams fetch larger chunks of memory (16 KiB by default) from the C++ side.
The cursor mimics that mechanism and locally cache a proper size of data in memory to be consumed when required. The cache size is still configurable.
async version of the iterable protocol.// Message we will print: Hello Cursor
import { open } from 'fs/promises'
import { FileCursor } from 'file-cursor'
import { fileURLToPath } from 'url'
// Open this file
const fileHandle = await open(fileURLToPath(import.meta.url))
try {
// Create the cursor
const cursor = new FileCursor({ fileHandle })
// Skip first 26 bytes
cursor.skip(26)
// Seek for the next 12 bytes
const buffer = await cursor.seek(12)
// Logs "Hello Cursor"
console.log(buffer.toString())
} finally {
// Close the file descriptor when done
await fileHandle.close()
}
new FileCursor(options)Either fd or fileHandle option must be provided.
options <Object>
[fd]: File descriptor got from fs.open.[fileHandle]: Instance of FileHandle got from fsPromises.open.[bufferSize] <Number>: Internal buffer size in bytes, defaults to 16 KiB.[position] <Number>: Initial cursor position (index), defaults to 0.FileCursor::fdUsed file descriptor.
FileCursor::bufferSizeInternal buffer size in bytes.
FileCursor::positionGets or sets current cursor position (index).
FileCursor::eofReturns true (getter) when End Of File is reached.
FileCursor::seek(size)Seeks bytes from the file and moves the cursor onward accordingly.
Guarantees at most a single fs.read().
length <Number> Number of bytes to seek.<Promise> Fulfills with the read bytes.FileCursor::set(position)Alias for position setter.
position <Number> Position (index) to jump on.<FileCursor>FileCursor::skip(offset)Skips a number of bytes from being read.
offset <Number> Number of bytes to skip.<FileCursor>FileCursor::Symbol.AsyncIterableFileCursor class also implements the async version of the iteration protocol.
for await (const buffer of cursor) {
console.log(`read ${buffer.bytesLength} bytes`)
console.log(`new position: ${cursor.position}`)
}
console.log(buffer.eof) // true
FAQs
Binary file cursor for Node.js
The npm package file-cursor receives a total of 8 weekly downloads. As such, file-cursor popularity was classified as not popular.
We found that file-cursor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.