Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

diskette

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

diskette

Stream buffers and strings efficiently in-memory

  • 1.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

Diskette

Build Status Dependency Status

Diskette is a virtual file format that allows for efficient in-memory reads and writes. Files can be constructed from any buffer or string and they are fully streamable. As a consequence, any buffer or string can be streamed as if it was a regular file.

Projects making use of it:

  • Comet

Your project here?

let diskette = require('diskette')

let file = new diskette.File({
  blockLength: 20
})

file.append('yo bruh\n')
file.append('i heard you like files\n')
file.write(4, 'dude')

let rest = new File('so i made files in memory that can be piped to just about anything\n')
let restStream = new diskette.ReadableFileStream(rest)

let out = new diskette.WritableFileStream(file)

restStream.pipe(out)

restStream.on('end', () => {
  file.append('hope you like it')
})

let s = new diskette.ReadableFileStream(file)
s.pipe(process.stdout)

Result:

yo dude 
i heard you like files
so i made files in memory that can be piped to just about anything
hope you like it

API

File

new File([content][, options])

Create a new file which has its contents stored in-memory, optionally filled with content, and with one of the following options:

  • blockLength: the size of one block

Note: content can be omitted.

file.size

The total length of the file, in bytes.

file.write(position, bufferOrString[, bufferStart][, bufferEnd])

Writes the content of buffer between the given indices to the given position. If no indices are provided, the enitre content of the buffer is written to file.

file.append(bufferOrString[, bufferStart][, bufferEnd])

Just like file.write, except that it appends data to the end of the file.

file.read(position, buffer, bufferStart, bufferEnd)

Reads content of file starting at the given position to the given buffer, optionally limited by two indices denoting the start and the end position of the buffer.

file.buffer([freeSpacePreceding = 0][, freeSpaceFollowing = 0])

Get a buffer that holds the content of file. Optionally make the buffer contain freeSpacePreceding and freeSpaceFollowing of free space.

file.toString([enc])

Convert the file to a string representation, using the specified encoding. Defaults to utf8.

file.allocateBlock()

Allocates a new block for writing content. This method is automatically called by the class, and generally should not be used.

file.totalLength()

Returns the total space the file occupies in-memory, including unused free space.

file.clear()

Clears all content of file by destroying the blocks, making it seem like an empty file was just created.

ReadableFileStream

new ReadableFileStream(file[, options])

Constructs a new readable stream of which data of file can be read. The options are:

  • chunkSize: how much data to stream in one cycle. Use -1 to make the chunk as large as possible (possibly the enitre file content). Defaults to -1.
  • startPosition: an offset in the file to start reading from. Defaults to 0.

WritableFileStream

new WritableFileStream(file[, options])

Constructs a new writable stream that writes data to file starting at the given position.

Similar projects

Keywords

FAQs

Package last updated on 07 Jun 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc