Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/random-access-storage/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
https://github.com/random-access-storage/random-access-memory
Last synced: 3 months ago
JSON representation
Exposes the same interface as random-access-file but instead of writing/reading data to a file it maintains it in memory
- Host: GitHub
- URL: https://github.com/random-access-storage/random-access-memory
- Owner: random-access-storage
- License: mit
- Created: 2016-04-16T19:55:29.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-03-21T13:00:24.000Z (10 months ago)
- Last Synced: 2024-05-13T16:23:58.376Z (9 months ago)
- Language: JavaScript
- Size: 43 KB
- Stars: 116
- Watchers: 5
- Forks: 25
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-dat - random-access-memory - same as `random-access-file` but maintains data in memory (Dat Core Modules / Storage)
README
# random-access-memory
Exposes the same interface as [random-access-file](https://github.com/mafintosh/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
``` js
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`:
```js
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