Security News
How Threat Actors are Abusing GitHub’s File Upload Feature to Host Malware
GitHub is susceptible to a CDN flaw that allows attackers to host malware on any public repository.
fstorm
Advanced tools
Readme
writing file like a storm , but always get the expected result
A very very small idea for writing file more 'safe' and 'super fast', inspired by steno, but more efficient and sensible.
fstorm is very suitable to be used when you need to excute frequently writing to same file.
Take writeFileSync
, writeFile
, steno
for comparison.
You can also find this benchmark in benchmark folder
10000x
100000x
1000000x
steno will pending without any response, the same as writeFile
and writeFileSync
About writeFile
In steno's page. It mentioned that writeFile
only take 20ms to writeFile, It is compeletely wrong. In fact, when you run fs.writeFile(..)
, It is only represent that the code is over, but file haven't been compelete yet. Althought not fast as expected, but it is still much faster than fs.writeFileSync
About steno
steno's setCallback and write(content, callback) are both meanless for hook the content after writting.
About writeFileSync
It is really sloooooooooooooooow..., but it is really reliable, beacuse it execute every file writing one by one..
fstorm!!
Now, There is a more reasonable choice when you need to writing file frequently, only the last one will be kept, and it is dead fast beacuse some trick to avoid unnecessary operation.
source code
var benchmarks = {
"writeFileSync": function(time, cb){
var filename = f("writeFileSync.txt");
var k = 0;
function compelete(){
k++
if( (k >= time) && cb) cb()
}
for (var i = 0; i < time; i++) {
fs.writeFileSync(filename, i)
compelete()
}
},
"writeFile": function(time, cb){
var filename = f("writeFile.txt");
var k = 0;
function compelete(){
k++;
if( (k >= time) && cb) cb()
}
for (var i = 0; i < time; i++) {
fs.writeFile( filename , i, compelete)
}
},
// I try setCallback for steno, it is also fail to get correct content.
"steno": function(time, cb){
var filename = f("steno.txt");
var sfile = steno(filename);
var k =0;
function compelete(){
k++;
if( (k >= time) && cb) cb()
}
for (var i = 0; i < time; i++) {
sfile.write(i, compelete)
}
},
"fstorm": function( time, cb ){
var filename = f("fstorm.txt");
var k =0;
var fwriter = fstorm(filename);
fwriter.on('end', cb) // emitted when a squence is over
for (var i = 0; i < time; i++) {
fwriter.write(i)
}
}
}
npm install fstorm
var fstorm = require('fstorm');
var writer = fstorm('./file3.txt');
writer.on('end', function(){
assert(fs.readFileSync('./file3.txt') === '7')
})
writer
.write('1')
.write('2')
.write('3')
.write('4')
.write('5')
.write('6')
process.nextTick(function(){
writer
.write('7')
})
fstorm(filename)
return a writer instance
var writer = fstorm(filename);
writer.write( content[, options] [, callback])
fs.writeFile(filename, options, callback)
. the options will be passed to it. default is 'utf8'Example
writer.write('1', function(err, status){
console.log(status)// ===> 0
})
writer.write('2', function(err, status){
console.log(status)// ===> 1
})
__FstormWriter is a SubClass of EventEmitter. __
Temporary, only end
and error
is emitted by writer, mean that writer is stable (or no new operation is blocked).
writer.on('end', function(content){
console.log(content === '2') // true
})
writer.write('1')
writer.write('2')
var writer = fstorm('.folder/not/exists/db.json')
writer.on('error', function(err){
assert(err.code === 'ENOENT') // true
})
writer.write('2')
benchmark
npm run benchmark
test
npm test
MITTTTTTTTTTTTTTTTTT.
FAQs
writing file more efficient and safety with no pain
The npm package fstorm receives a total of 342 weekly downloads. As such, fstorm popularity was classified as not popular.
We found that fstorm 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
GitHub is susceptible to a CDN flaw that allows attackers to host malware on any public repository.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.