New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

larvitfiles

Package Overview
Dependencies
Maintainers
3
Versions
142
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

larvitfiles

Storage of files with an API and database to use in web environments

  • 3.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
305
increased by134.62%
Maintainers
3
Weekly downloads
 
Created
Source

Build Status Dependencies

larvitfiles

Installation

npm i larvitfiles;

Usage

Add file from buffer

const	lFiles	= require('larvitfiles'),
	db	= require('larvitdb'),
	fs	= require('fs');

db.setup(conf); // Only needed once per script. See https://github.com/larvit/larvitdb for details

fs.readFile('/some/file.txt', function (err, data) {
	let file;

	if (err) throw err;

	file = new lFiles.File({
		'slug':	'slug/foo/bar.txt',
		'data':	data,
		'metadata':	{'metadata1': 'metavalue1', 'metadata2': ['multiple', 'values']}
	}, function (err) {
		if (err) throw err;

		file.save(function (err) {
			if (err) throw err;

			console.log('file saved with uuid: ' + file.uuid);
			console.log('metadata: ' + JSON.stringify(file.metadata));
			console.log('slug: ' + file.slug);
		});
	});
});

Get file from storage

const	lFiles	= require('larvitfiles'),
	db	= require('larvitdb');

let file;

db.setup(conf); // Only needed once per script. See https://github.com/larvit/larvitdb for details

file = new lFiles.File({'slug': 'slug/foo/bar.txt'}, function (err) {
	if (err) throw err;

	console.log('file saved with uuid: ' + file.uuid);
	console.log('metadata: ' + JSON.stringify(file.metadata));
	console.log('slug: ' + file.slug);
	// file data in file.data
});

Remove a file from storage

const	lFiles	= require('larvitfiles'),
	db	= require('larvitdb');

let file;

db.setup(conf); // Only needed once per script. See https://github.com/larvit/larvitdb for details

file = new lFiles.File({'slug': 'slug/foo/bar.txt'}, function (err) {
	if (err) throw err;

	file.rm(function (err) {
		if (err) throw err;

		console.log('File is now removed from storage');
	});
});

List files in storage

List all files

const	lFiles	= require('larvitfiles'),
	db	= require('larvitdb');

let files;

db.setup(conf); // Only needed once per script. See https://github.com/larvit/larvitdb for details

files = new lFiles.Files();
files.get(function (err, result) {
	if (err) throw err;

	console.log(result); // Object list of files, uuid as key and slugs, uuids and metadata, but NOT file data as values.
});

Filter list based on metadata

const	lFiles	= require('larvitfiles'),
	db	= require('larvitdb');

let files;

db.setup(conf); // Only needed once per script. See https://github.com/larvit/larvitdb for details

files = new lFiles.Files();

// This will only return files with metadata
// 1) "foo" = "bar" (and possibly other values as well)
// and
// 2) "zoo" = anything
files.filter.metadata.foo = 'bar';
files.filter.metadata.zoo = true;
files.get(function (err, result) {
	if (err) throw err;

	console.log(result); // Object list of files, uuid as key and slugs, uuids and metadata, but NOT file data as values.
});

And if several values should exist on a single metadata do this:

const	lFiles	= require('larvitfiles'),
	db	= require('larvitdb');

let files;

db.setup(conf); // Only needed once per script. See https://github.com/larvit/larvitdb for details

files = new lFiles.Files();

// This will only return files with metadata
// 1) "foo" = "bar" (and possibly other values as well)
// and
// 2) "foo" = "baz" (and possibly other values as well)
files.filter.metadata.foo = ['bar', 'baz'];
files.get(function (err, result) {
	if (err) throw err;

	console.log(result); // Object list of files, uuid as key and slugs, uuids and metadata, but NOT file data as values.
});

Keywords

FAQs

Package last updated on 04 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc