Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
generic-filehandle2
Advanced tools
uniform interface for accessing binary data from local files, remote HTTP resources, and browser Blob data
Provides a uniform interface for accessing binary data from local files, remote HTTP resources, and Blob data in the browser.
import { LocalFile, RemoteFile, BlobFile } from 'generic-filehandle2'
// operate on a local file path
const local = new LocalFile('/some/file/path/file.txt')
// operate on a remote file path
const remote = new RemoteFile('http://somesite.com/file.txt')
// operate on blob objects
const blobfile = new BlobFile(new Blob([some_data], { type: 'text/plain' }))
// read slice of file, works on remote files with range request
const buf1 = await remote.read(10, 10)
// read whole file
const buf2 = await remote.readFile()
Important: under node.js, you should supply a fetch function to the RemoteFile constructor
import { RemoteFile } from 'generic-filehandle2'
import fetch from 'node-fetch'
const remote = new RemoteFile('http://somesite.com/file.txt', { fetch })
async read(length: number, position: number=0, opts?: Options): Promise<Uint8Array>
Returns a Promise for the Uint8Array
async readFile(opts?: Options): Promise<Uint8Array | string>
Returns a Promise for Uint8Array or string containing the contents of the whole file.
async stat() : Promise<{size: number}>
Returns a Promise for an object containing as much information about the file as
is available. At minimum, the size
of the file will be present.
The Options object for the constructor, read
and readFile
can contain abort
signal to customize behavior. All entries are optional.
<AbortSignal>
- an AbortSignal that is passed to remote file fetch()
API or other file readers<Object <string, string> >
- extra HTTP headers to pass to remote
file fetch() API<Object>
- extra parameters to pass to the remote file fetch() API<Function>
- a custom fetch callback, otherwise defaults to the
environment (initialized in constructor)<string>
- if specified, then this function returns a string.
Otherwise it returns a Uint8Array. Currently only utf8
encoding is
supported.The Options object for readFile
can also contain an entry encoding
. The
default is no encoding, in which case the file contents are returned as a
Uint8Array. Currently, the only available encoding is utf8
, and specifying
that will cause the file contents to be returned as a string. For compatibility
with the Node API, the readFile
method will accept the string "utf8" instead
of an Options object.
This module attempts to modernize the original generic-filehandle API by not requiring node.js Buffer polyfill, and in doing so disconnected somewhat with the true Node.js fs API https://github.com/GMOD/generic-filehandle
FAQs
uniform interface for accessing binary data from local files, remote HTTP resources, and browser Blob data
The npm package generic-filehandle2 receives a total of 85 weekly downloads. As such, generic-filehandle2 popularity was classified as not popular.
We found that generic-filehandle2 demonstrated a healthy version release cadence and project activity because the last version was released less than 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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.