1.0.3 • Published 3 years ago

memory-disk v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

MemoryDisk.js

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()
1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago