Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Handles reads / writes on disk image files.
Handles reads / writes on disk image files.
Warning: The API exposed by this library is still forming and can change at any time!
new FileDisk(fd, readOnly, recordWrites, recordReads, discardIsZero=true)
fd
is a file descriptor returned by fs.open
readOnly
a boolean (default false
)recordWrites
, a boolean (default false
); if you use readOnly
without
recordWrites
, all write requests will be lost.recordReads
, a boolean (default false
): cache reads in memorydiscardIsZero
, a boolean (default true
): don't read discarded regions,
return zero filled buffers instead.FileDisk.getCapacity()
: Promise<Number>
FileDisk.read(buffer, bufferOffset, length, fileOffset)
: Promise<{ bytesRead: Number, buffer: Buffer }>
FileDisk.write(buffer, bufferOffset, length, fileOffset)
: Promise<{ bytesWritten: Number, buffer: Buffer }>
FileDisk.flush()
: Promise<void>
FileDisk.discard(offset, length)
: Promise<void>
FileDisk.getStream([position, [length, [highWaterMark]]])
: Promise<stream.Readable>
position
start reading from this offset (defaults to 0)length
read that amount of bytes (defaults to (disk capacity - position))highWaterMark
(defaults to 16384, minimum 16) is the size of chunks that
will be readFileDisk.getDiscardedChunks()
returns the list of discarded chunks. Each chunk
has a start
and end
properties. end
position is inclusive.
FileDisk.getRanges(blockSize)
: Promise<Range[]>
Range
s: { offset: number, length: number }
.S3Disk
has been moved to a separate repository.
const Bluebird = require('bluebird');
const filedisk = require('file-disk');
Bluebird.using(filedisk.openFile('/path/to/some/file', 'r+'), async (fd) => {
const disk = new filedisk.FileDisk(fd)
// get file size
const size = await disk.getCapacity();
console.log("size:", size);
const buf = Buffer.alloc(1024);
// read `buf.length` bytes starting at 0 from the file into `buf`
const { bytesRead, buffer } = await disk.read(buf, 0, buf.length, 0);
// write `buffer` into file starting at `buffer.length` (in the file)
await disk.write(buf, 0, buf.length, buf.length);
// flush
await disk.flush();
});
const Bluebird = require('bluebird');
const filedisk = require('file-disk');
const BUF = Buffer.alloc(1024);
Bluebird.using(filedisk.openFile('/path/to/some/file', 'r'), async (fd) => {
const disk = new filedisk.FileDisk(fd, true, true);
let bytesRead, bytesWritten, buffer;
// read `BUF.length` bytes starting at 0 from the file into `BUF`
{ bytesRead, buffer } = await disk.read(BUF, 0, BUF.length, 0);
// write `buffer` into file starting at `buffer.length` (in the file)
{ bytesWritten, buffer } = await disk.write(buffer, 0, buffer.length, buffer.length);
const buf2 = Buffer.alloc(1024);
// read what we've just written
{ bytesRead, buffer } = await disk.read(buf2, 0, buffer.length, 0);
// writes are stored in memory
assert(BUF.equals(buffer));
const stream = await disk.getStream();
// pipe the stream somewhere
await new Bluebird((resolve, reject) => {
stream.pipe(someWritableStream)
.on('close', resolve)
.on('error', reject);
});
});
FAQs
Handles reads / writes on disk image files.
The npm package file-disk receives a total of 7,743 weekly downloads. As such, file-disk popularity was classified as popular.
We found that file-disk 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.