npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

level-store

v3.11.0

Published

A streaming storage engine based on LevelDB.

Downloads

286

Readme

level-store

A streaming storage engine based on LevelDB. It is

  • faster than the fs module
  • local in contrast to Amazon S3
  • streaming from the first byte in contrast to Amazon S3
  • appending values when desired
  • resuming reads when something failed
  • in-process

Build Status downloads

Only need in-memory persistence and no resuming? Check out enstore.


Usage

Store a file in LevelDB under the key file and read it out again:

var levelup = require('level');
var Store = require('level-store');
var fs = require('fs');

var store = Store(levelup('/tmp/level-store'));

fs.createReadStream(__dirname + '/file.txt')
  .pipe(store.createWriteStream('file'))
  .on('close', function () {
    // file.txt is stored in leveldb now
    store.createReadStream('file').pipe(process.stdout);
  });

Live persistence

If you want to persist a stream and read from it at the same time, without reading what didn't get stored yet, you can do it like this:

// first start reading from the stored version
storage.createReadStream('stream', { live: true }).pipe(someWhere);
// then put your stream into the store
stream.pipe(storage.createWriteStream('stream'));

Resuming

When reading fails you might not want to start over again completely but rather resume after the last chunk you received. First, pass index: true as an option so you don't only get the stored chunks but also their index in the store:

store.createReadStream('file', { index: true }).on('data', console.log);
// => { index: 1363783762087, data : <Buffer aa aa> }

Now you only need store the timestamp of the last read chunk in a variable and you can resume reading after an error, passing { gt: index }:

store
  .createReadStream('file', { gt: 1363783762087, index: true })
  .on('data', console.log);
// => { index: 1363783876109, data : <Buffer bb bb> }

Indexes

You can choose from several indexing mechanisms, which are from fastest to slowest:

  • timestamp: The default index. Uses timestamps of when a chunk was written. Fast and already enough for resuming. Activate with Store(db, { index : 'timestamp' }).
  • chunks: The index is the number of chunks already written, starting at 0. Activate with Store(db, { index : 'chunks' }).
  • TODO: bytelength: The index is the bytelength of what has already been written under the given key. Slow, but very flexible. Activate with Store(db, { index : 'bytelength' }).

Capped streams

If you don't want your stream to grow infinitely and it's ok to cut old parts off, use { capped : x } to limit to stream to x chunks:

store.createWriteStream('file', { capped : 3 }).write('...');

API

Store(db[, opts])

Returns a level-store instance.

db is an instance of LevelUp.

If opts.index is set, that indexing mechanism is used intead of the default one (timestamp).

store#createReadStream(key[, opts])

A readable stream that replays the stream stored at key.

Possible options are:

  • index (Boolean|String): If true, don't emit raw chunks but rather objects having index and data fields. If a String, override the index passed to Store().
  • gt (Number|String): Emit chunks that have been stored after the given position.
  • gte (Number|String): Emit chunks that have been stored at or after the given position.
  • lt (Number|String): Emit chunks that have been stored before the given position.
  • lte (Number|String): Emit chunks that have been stored at or before the given position.
  • live (Boolean): If true, the stream will stay open, emitting new data as it comes in.
  • reverse (Boolean): If true, chunks will be emitted in reverse order.
  • limit (Number): Receive max. limit chunks.
  • valueEncoding (String): Use a specific encoding for values.

store#createWriteStream(key[, opts])

A writable stream that persists data written to it under key. If something exists under key already it will be deleted.

Possible options are:

  • append (Boolean): If true, possibly already existing data stored under key will be appended rather than replaced.
  • capped (Number): If set, cap the stream to x chunks.
  • index (String): Override the index passed to Store().

store#createKeyStream(opts)

A readable stream that emits all the keys of all streams that are stored.

Possible options are:

  • reverse (Boolean)

store#get(key[, opts], cb)

Async version of createReadStream.

store#set(key, value[, opts], cb)

Async version of createWriteStream.

store#keys(cb)

Async version of createKeyStream, without reverse sorting capability.

store#delete(key[, cb])

Delete everything stored under key. Returns an error if nothing was stored under key.

store#reset(key[, cb])

Delete everything stored under key. Doesn't return an error if nothing was stored under key.

store#exists(key, cb)

Check if key exists and call cb with (err, exists).

store#head(key[, opts], cb)

Get the last chunk stored under key. opts are treated like in db#createReadStream. cb gets called with (err, chunk).

store#append(key, value[, opts][, cb])

Sugar for appending just one value to key.

If opts.index is set that overrides the index passed to Store().

Installation

With npm do

$ npm install level-store

License

Copyright (c) 2013 Julian Gruber <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.