memory-disk
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

Manage files in memory and automatically synchronize with disk.

Usage


  • Javascript
const fs = require('fs')
const { MemoryDisk } = require('memory-disk')

// The real filesystem path to be referenced. (only directory)
const path = './data'

// Whether to get all directory information in the directory
const recursive = true

const memoryDisk = new MemoryDisk(path, recursive)


const testPath = './data/text.txt';

// Save to memory. (After just 5 minutes, it automatically saves to the physical disk.)
memoryDisk.write(testPath, "Hello memory-disk world!")

// Read data. If it is not in memory, it is fetched from the real filesystem.
const data = memoryDisk.read(testPath)

// If there is no .write() or .read() for 5 minutes, it is automatically saved to the real filesystem and deleted from memory.
console.log('data:', data)

console.log('Is real filesystem exists? (before .saveDisk())', fs.existsSync(testPath));
memoryDisk.saveDisk(testPath)
console.log('Is real filesystem exists? (after .saveDisk())', fs.existsSync(testPath));

// Memory clear
memoryDisk.clear()
  • Typescript
import fs from 'fs';
import { MemoryDisk } from "memory-disk";

// The real filesystem path to be referenced. (only directory)
const path = './data'

// Whether to get all directory information in the directory
const recursive = true

const memoryDisk = new MemoryDisk(path, recursive)


const testPath = './data/text.txt';

// Save to memory. (After just 5 minutes, it automatically saves to the physical disk.)
memoryDisk.write(testPath, "Hello memory-disk world!")

// Read data. If it is not in memory, it is fetched from the real filesystem.
const data = memoryDisk.read(testPath)

// If there is no .write() or .read() for 5 minutes, it is automatically saved to the real filesystem and deleted from memory.
console.log('data:', data)

console.log('Is real filesystem exists? (before .saveDisk())', fs.existsSync(testPath));
memoryDisk.saveDisk(testPath)
console.log('Is real filesystem exists? (after .saveDisk())', fs.existsSync(testPath));

// Memory clear
memoryDisk.clear()

Readme

Keywords

Package Sidebar

Install

npm i memory-disk

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

20.9 kB

Total Files

16

Last publish

Collaborators

  • nevation