
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Sugar to open and close a file descriptor.
const open = require('fs-lotus')
, fs = require('fs')
const readExactly = function (filename, pos, length, done) {
open(filename, 'r', function (err, fd, close) {
if (err) return done(err)
fs.read(fd, Buffer(length), 0, length, pos, function (err, bytesRead, buf) {
if (err) return close(done, err)
if (bytesRead !== length) {
return close(done, new Error('End of file'))
}
close(done, null, buf)
})
})
}
The open
function has the same signature as fs.open(path, flags[, mode], callback)
. Except that callback
also receives a close(callback, err, ...args)
function, which calls fs.close
for you. An error from fs.close
(if any) will be combined with your error (if any).
This pattern ensures that our readExactly
function doesn't leak fd's.
readExactly('readme.md', 0, 10, function (err, buf) {
console.log(buf.toString()) // '# fs-lotus'
})
readExactly('readme.md', 1e5, 10, function (err, buf) {
console.log(err.toString()) // 'Error: End of file'
})
With npm do:
npm install fs-lotus
MIT © Vincent Weevers
FAQs
Sugar to open and close a file descriptor
The npm package fs-lotus receives a total of 1,464 weekly downloads. As such, fs-lotus popularity was classified as popular.
We found that fs-lotus 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
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.