# 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

Latest version **6.2.1** (published 2024-03-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install random-access-memory
pnpm add random-access-memory
yarn add random-access-memory
bun add random-access-memory
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.2.1 |
| Published | 2024-03-21 |
| First published | 2016-04-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 117 |
| Author | Mathias Buus |
| Maintainers | mafintosh |

## Links

- npm: https://www.npmjs.com/package/random-access-memory
- Repository: https://github.com/random-access-storage/random-access-memory
- Issues: https://github.com/random-access-storage/random-access-memory/issues
- npm.io page: https://npm.io/package/random-access-memory

## Dependencies (3)

- [b4a](https://npm.io/package/b4a.md) ^1.6.0
- [is-options](https://npm.io/package/is-options.md) ^1.0.2
- [random-access-storage](https://npm.io/package/random-access-storage.md) ^3.0.0

## Recent versions

- 6.2.1 (latest) — 2024-03-21
- 6.2.0 — 2023-04-11
- 6.1.0 — 2022-11-18
- 6.0.0 — 2022-09-14
- 5.0.1 — 2022-08-23
- 5.0.0 — 2022-07-13
- 4.1.0 — 2022-04-21
- 4.0.1 — 2022-04-14
- 4.0.0 — 2021-11-16
- 3.1.4 — 2021-11-16
- 3.1.3 — 2021-11-04
- 3.1.2 — 2021-01-14
- 3.1.1 — 2018-12-05
- 3.1.0 — 2018-12-05
- 3.0.0 — 2018-04-21
- … 7 more at https://npm.io/package/random-access-memory/versions

## 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

---
_Source: https://npm.io/package/random-access-memory · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
