Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
File Bin is an exercise in writing an abstraction for file system access in Node.js.
We're doing a project at the Turing School of Software and Design building a note-taking application using Ember and Electron. Ember Data was designed to work with APIs—not the filesystem.
fs.readdir
returns an array of strings. APIs normally return an array of objects.fs.read
doesn't work on directories.const FileBin = require('file-bin');
let fileBin = new FileBin('/base-directory', ['.md', '.txt']);
The constructor takes two arguments:
You can leave either blank. If you do, then it will default to process.cwd()
and allowing all extensions respectively.
Instances have a #find
method that will look for a file with a given file name and return a promise.
fileBin.find('README.md').then(file => {
console.log(file);
});
The resuling file has two properties: id
and content
. id
is the file name. content
is the content of the file.
#all
will find all of the files in the base directory. If you provided an array of valid extensions, then it will filter by those extenions. The resulting files are fulling instantiated objects—just like #find
above.
Note: At this moment, File Bin does not support subdirectories. They are omitted.
fileBin.all().then(files => console.log(files));
#write
takes two arguments fileName
and content
. It will write the file to the filesystem and then return the object via a promise.
fileBin.write('CONTRIBUTORS.md', 'Pull requests accepted')
.then(file => console.log(file));
#copy
takes two arguments sourceFile
and copyFile
. It will write the copied file to the filesystem and then return the copy via a promise.
fileBin.copy('orignal.md', 'original-copy.md')
.then(copy => console.log(copy));
#rename
takes two arguments oldFileName
and newFileName
. It will rename the old file to the specified new file name and return the file object via a promise.
fileBin.rename('old-name.md', 'new-name.md')
.then((file, oldFileName, newFileName) => console.log(`${oldFileName} was successfully renamed to ${newFileName}.`)
#destroy
takes a single argument of the fileName
that you want to delete. It will delete the specified file and return the fileName
via a promise.
fileBin.destroy('filename.md')
.then(console.log(`filename.md`))
#copy
takes two arguments sourceFile
and copyFile
. It will write the copied file to the filesystem and then return the copy via a promise.
fileBin.copy('orignal.md', 'original-copy.md')
.then(copy => console.log(copy));
#getBaseDirectory
can be called on a FileBin instance and it will return the current base directory.
#setBaseDirectory('/new/base')
takes in a directory as an argument and will update the FileBin's base directory to the given directory.
#setBaseDirectory
will emit an event that contains the oldDirectory and the newDirectory.
var fileBin = new FileBin('/some/directory')
console.log(fileBin.getBaseDirectory()); // --> /some/directory;
fileBin.setBaseDirectory('/new/base');
console.log(fileBin.getBaseDirectory()); // --> /new/base;
FAQs
An abstraction for accessing the filesystem in Node.js.
The npm package file-bin receives a total of 5 weekly downloads. As such, file-bin popularity was classified as not popular.
We found that file-bin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.