ls-chunk-store

2.0.0 • Public • Published

ls-chunk-store travis npm downloads

Greenkeeper badge

Browser localStorage chunk store that is abstract-chunk-store compliant

abstract chunk store

Features

  • Chunks that don't fit in localStorage remain in memory
  • Works as a persistent cache of chunks
  • Oldest ls-chunk-store chunks are removed when store is full

Install

npm install ls-chunk-store

You can also use the browserified version from jsDelivr:

<script src="https://cdn.jsdelivr.net/ls-chunk-store/latest/ls-chunk-store.min.js"></script>

Build

The following command will build ls-chunk-store.min.js in the dist folder

npm run-script build

The following command will build ls-chunk-store.js in the root folder

npm run-script build-dev

Usage

Generate random prefix

var LSChunkStore = require('ls-chunk-store')
 
var chunks = new LSChunkStore(10)

Use specified prefix

var LSChunkStore = require('ls-chunk-store')
 
var chunks = new LSChunkStore(10, {
  prefix: 'myFile.txt'
})

put, get, close, destroy

chunks.put(0, new Buffer('0123456789'), function (err) {
  if (err) throw err
 
  chunks.get(0, function (err, chunk) {
    if (err) throw err
    console.log(chunk) // '0123456789' as a buffer
 
    chunks.close(function (err) {
      if (err) throw err
      console.log('storage is closed')
 
      chunks.destroy(function (err) {
        if (err) throw err
        console.log('files is deleted')
      })
    })
  })
})

License

MIT. Copyright (c) Diego Rodríguez Baquero.

Package Sidebar

Install

npm i ls-chunk-store

Weekly Downloads

7

Version

2.0.0

License

MIT

Last publish

Collaborators

  • diegorbaquero