Meet npm Pro: unlimited public & private packages + package-based permissions.Learn more »

ramdisk

0.3.1 • Public • Published

RAM Disk

npm npm downloads build status

Install via npm

$ npm install ramdisk

What? Why? How does it work?!

This is just the easiest & quickest cross-platform solution that I just happened to come up with at the time. I mainly need it to test file system implementations and the like. The API is pretty much the same as blockdevice's, which features some crappy documentation on it. It's most likely worse than just reading the code. I'll work on it, I promise.

Thing is, it allocates sparsely (with the worst possible allocator (if you can even call it that) ever written to date) - meaning - you can specify 4 GB as size & you won't occupy 4 GB of memory, until you actually write to every sector.

Usage

var RamDisk = require( 'ramdisk' )
// Options, with their defaults
var device = new RamDisk({
  // Emulated (?) device block size
  blockSize: 512,
  // Cluster size. It allocates in these.
  clusterSize: 4096,
  // The grand total (absolutely imaginary) size
  // of the entire contraption!
  size: 10 * 1024 * 1024,
})
// Supplying a buffer to .readBlocks() is optional
var buffer = new Buffer( device.blockSize )
 
device.readBlocks(
  fromLBA, toLBA, buffer,
  function( error, buffer, bytesRead ) {
    // ...
  }
)

Install

npm i ramdisk

DownloadsWeekly Downloads

7

Version

0.3.1

License

MIT

Last publish

Collaborators

  • avatar