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.
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(callback(err, size))
callback(err, size)
will be called with the size of the disk image in
bytesFileDisk.read(buffer, bufferOffset, length, fileOffset, callback(err, bytesRead, buffer))
FileDisk.write(buffer, bufferOffset, length, fileOffset, callback(err, bytesWritten))
FileDisk.flush(callback(err))
FileDisk.discard(offset, length, callback(err))
FileDisk.getStream(position, length, highWaterMark, callback(err, stream))
position
start reading from this offset (null
means zero)length
read that amount of bytes (null
means read until the end)highWaterMark
[optional, defaults to 16384, minimum 16] is the size of
chunks that will be readcallback(err, stream)
will be called with a readable stream of the disk
contentFileDisk.getDiscardedChunks()
returns the list of discarded chunks. Each chunk
has a start
and end
properties. end
position is inclusive.
FileDisk.getBlockMap(blockSize, callback(err, blockmap))
using the disk's
discarded chunks and the given blockSize, it calls back with
a BlockMap
.
Be careful to how you use Disk
's discardIsZero
option as it may change the
blockmap ranges checksums if discarded regions not aligned with blockSize
contain anything else than zeros on the disk.
S3Disk
acts like FileDisk
except it reads the image file from S3 instead of
the filesystem. S3Disk
has readOnly
and recordWrites
enabled. This can
not be changed.
new S3Disk(s3, bucket, key, recordReads, discardIsZero=true)
s3
is an s3 connection.bucket
is the S3 bucket to use.key
is the key (file name) to use in the bucket.For more information about S3Disk parameters see the aws documentation
const Promise = require('bluebird');
const filedisk = Promise.promisifyAll(require('file-disk'), { multiArgs: true });
Promise.using(filedisk.openFile('/path/to/some/file', 'r+'), function(fd) {
const disk = new filedisk.FileDisk(fd)
// get file size
return disk.getCapacityAsync()
.spread(function(size) {
console.log("size:", size);
const buf = Buffer.alloc(1024);
// read `buf.length` bytes starting at 0 from the file into `buf`
return disk.readAsync(buf, 0, buf.length, 0);
})
.spread(function(bytesRead, buf) {
// write `buf` into file starting at `buf.length` (in the file)
return disk.writeAsync(buf, 0, buf.length, buf.length);
})
.spread(function(bytesWritten) {
// flush
return disk.flushAsync();
});
});
const Promise = require('bluebird');
const filedisk = Promise.promisifyAll(require('file-disk'), { multiArgs: true });
const buf = Buffer.alloc(1024);
Promise.using(filedisk.openFile('/path/to/some/file', 'r'), function(fd) {
const disk = new filedisk.FileDisk(fd, true, true);
// read `buf.length` bytes starting at 0 from the file into `buf`
return disk.readAsync(buf, 0, buf.length, 0);
.spread(function(bytesRead, buf) {
// write `buf` into file starting at `buf.length` (in the file)
return disk.writeAsync(buf, 0, buf.length, buf.length);
})
.spread(function(bytesWritten) {
const buf2 = Buffer.alloc(1024);
// read what we've just written
return disk.readAsync(buf2, 0, buf.length, 0);
});
.spread(function(bytesRead, buf2) {
// writes are stored in memory
assert(buf.equals(buf2));
})
.then(function() {
return disk.getStreamAsync(null, null);
})
.spread(function(stream) {
// pipe the stream somewhere
return new Promise(function(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,684 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.