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

df-storage

v1.0.0

Published

A node.js module for the file storage management

Downloads

23

Readme

DFStorage

Build Status npm version

DFStorage is a module for the storage of file in different way. Currently supports storage in file system and in MongoDb GridFs.

Project Home Page

##Quickstart

var storages = require('df-storage');
var myGridFs = new storages.GridFS(
    {db: someMongoDbConnection}
);
storages.setStorage('my-storage', myGridFs);

//...

var myStorage = storages.getStorage('my-storage');
myStorage.save(pathToSourceFile, uniqueID);

//...

function someMiddlwareFunc(req, res, next) {
  var myStorage = storages.getStorage('my-storage');
  myStorage.sendToResponse(req.query.uniqueID, res);
}

##FileFsStorage

var FileFs = require('df-storage').FileFS;

var fileFs = new FileFs({
  path: rootPath,
  deep : 3,
  contentType : 'text/html'
});
  • path, define the root path of the storage in the filesystem
  • deep, define the number of subfolders used for saving the file. (eg. If the file name/uid is someFileName and the deep value is equal to 3, will be saved in s/o/m/someFileName)
  • contentType, the default content type of the file saved

n addition to the original file will be saved another file containing metadata with the name someFileName.json.

  • filename, the name/uid of the file
  • contentType, The content type of the file
  • length, The size of the file
  • metadata, additional custom metadata

##GridFsStorage

var GridFs = require('df-storage').GridFS;

var gridFs = new GridFs({
  db: connectionManager.getConnection(),
  collectionRoot: 'my-collection-root',
  chunkSize: 10000,
  contentType: 'html/zip'
});
  • db, a mongodb conncetion
  • collectionRoot, the base name of the mongoDb collection used by the gridFs.
  • chunkSize, the default size of the chunk
  • contentType, the default content type of the file saved

in addition to the original file will be saved some metadata.

  • filename, the name/uid of the file
  • contentType, The content type of the file
  • chunkSize, the size of the chunk
  • length, The size of the file
  • metadata, additional custom metadata

##API

##save(originalPath, UID, options) -> Promise() Save a file from a source (originalPath) with the Id (UID)

  • originalPath, the source
  • UID, the UID in the storage
  • options:
    • metadata, additional custom metadata
    • chunkSize, the size of chunk (only in the GridFs)
    • contentType, the contentType

If chunkSize and contentType aren't defined the default values are used.

##load(UID, readStream) Load a file (UID) into the readStream

  • UID, the UID in the storage
  • readStream, a readStream

##sendToResponse(UID, response) Send the file directly to the responseObject

  • UID, the UID in the storage
  • response, http response object

Adds to the response data also contentType and fileSize

##loadMeta(UID) -> Promise(metadata) Load the metadata of the file

  • UID, the UID in the storage

##remove(UID) -> Promise() Remove the file

  • UID, the UID in the storage

##exists(UID) -> Promise(exists) Check if file exists

  • UID, the UID in the storage

#TODO

  • Improve documentation
  • Implement more storage (Eg. Amazon S3)
  • Implement methods for different storage comunication
    • Copy
    • Sync
  • Improve my English!! :)

#Contacts

#License Copyright 2014 Davide Fiorello MIT License (enclosed)