🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

random-access-memory

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

random-access-memory

Exposes the same interface as random-access-file but instead of writing/reading data to a file it maintains it in memory

6.2.1
latest
Source
npm
Version published
Weekly downloads
7.8K
-18.24%
Maintainers
1
Weekly downloads
 
Created
Source

random-access-memory

Exposes the same interface as random-access-file but instead of writing/reading data to a file it maintains it in memory. This is useful when running tests where you don't want to write files to disk.

npm install random-access-memory

Usage

const RAM = require('random-access-memory')
const file = new RAM()

file.write(0, Buffer.from('hello'), function () {
  file.write(5, Buffer.from(' world'), function () {
    file.read(0, 11, console.log) // returns Buffer(hello world)
  })
})

You can also initialize a RAM instance with a Buffer:

const file = new RAM(Buffer.from('hello world'))

If you want to mimick a folder on disk, you can use const createRAM = RAM.reusable().

This stores the created ram instances, ie ram = createRAM(name) in a map so they can be reopened with the same state, similar to working with files, but still backed by ram.

License

MIT

FAQs

Package last updated on 21 Mar 2024

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