Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
buffered-writer
Advanced tools
Node.js project
Version: 0.2.3
Node.js streams are not buffered, that is, when you write data to them you're doing multiple I/O calls. This module buffers the data that has to be written to disk and eases the buffer manipulation when you need to write data from different nature (strings, numbers, arrays or buffers).
npm install buffered-writer
var bw = require ("buffered-writer");
bw.open ("file")
.on ("error", function (error){
console.log (error);
})
.write ([0x00, 0x01, 0x02]) //Writes: 0x00, 0x01, 0x02
.write (new Buffer ([0x03, 0x04]), 1, 1) //Writes: 0x04
.write (0x0506) //Writes: 0x05, 0x06
.write ("↑a", 1) //Writes: a (0x61)
.close ();
When you call to open()
a Writer
instance is returned. This object inherits from EventEmitter
and wraps a WriteStream
. Only an error
event is emitted. When this ocurrs, the Writer
is closed automatically, you don't need to close it explicitly (if you try to do so you'll get another error, you cannot close twice).
bw.open(file[, settings])
Creates a Writer
and opens a stream to the given file. If the file doesn't exist it is created. The possible settings are:
Returns the new Writer
instance.
Writer#close([callback])
Flushes the remaining data and closes the Writer
. The callback doesn't receive any parameter.
Writer#flush(callback)
Flushes the current data. After the callback is executed it's safe to read back the written data, the data has been stored successfully. The callback doesn't receive any parameter.
This function is typically used when you need to ensure that the data is flushed to the disk at some point before closing the stream.
var out = bw.open ("file").write ("a");
//Default buffer size is 16KB so the "a" character is still in memory
//Let's force and flush it to disk
out.flush (function (){
fs.readFile ("file", function (error, data){
if (error) return console.log (error);
//data.toString () === "a"
out.close ();
});
});
Writer#line()
Writes a line, OS dependent, \r\n
on Windows, \n
otherwise.
Returns the Writer
instance to allow method chaining.
Writer#write(data[, offset[, length]])
Writes data. It's not flushed to the underlying I/O layer, it's queued to a buffer and when it's full it's flushed to the disk.
The data can be a Number, String, Array or Buffer.
open()
's encoding parameter is used.The offset and length specifies the slice of the given piece of data that will be written. By default offset is 0 and length is the last byte/character. The offset and length are applied to the string characters, not the bytes, for example, write("↑a", 1)
will write a
because offset is 1. Take into account that ↑
is encoded with 3 bytes in utf8.
Returns the Writer
instance to allow method chaining.
Writer#writeln(data[, offset[, length]])
Does the same as write()
but stringifies the data and concatenates an EOL, OS dependent, \r\n
on Windows, \n
otherwise.
FAQs
Writes buffered data to files
The npm package buffered-writer receives a total of 5 weekly downloads. As such, buffered-writer popularity was classified as not popular.
We found that buffered-writer 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.