Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
generic-filehandle
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. Implements a subset of the Node.js v10 promise-based FileHandle API.
import { LocalFile, RemoteFile, BlobFile } from 'generic-filehandle'
// 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_existing_buffer], { type: 'text/plain' }))
// read slice of file, works on remote files with range request, pre-allocate buffer
const buf = Buffer.alloc(10)
const { bytesRead } = await remote.read(buf, 0, 10, 10)
console.log(buf.toString())
// readFile, returns buffer
const buf = remote.readFile()
Important: under node.js, you should supply a fetch function to the RemoteFile constructor
import { RemoteFile } from 'generic-filehandle'
import fetch from 'node-fetch'
const remote = new RemoteFile('http://somesite.com/file.txt', { fetch })
Returns a Promise for the number of bytes read, and the data will be copied into the Buffer provided in the arguments.
Returns a Promise for a buffer or string containing the contents of the whole file.
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.
Closes the filehandle.
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 buffer. 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
buffer. 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 library implements a subset of the Node.js v10 promise-based FileHandle API.
FAQs
uniform interface for accessing binary data from local files, remote HTTP resources, and browser Blob data
The npm package generic-filehandle receives a total of 1,509 weekly downloads. As such, generic-filehandle popularity was classified as popular.
We found that generic-filehandle demonstrated a healthy version release cadence and project activity because the last version was released less than 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.