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 🙏

© 2025 – Pkg Stats / Ryan Hefner

fs-cdn

v0.1.0

Published

An adapter between fs and pkgcloud

Readme

fs-cdn

A streaming adapter between fs and pkgcloud

fs-cdn allows you to mirror basic native fs and pkgcloud functionality. It abstracts the interface into an intuitive set of methods for basic file operations on either your local filesystem and a storage provider supported by pkgcloud.

Getting Started

There are two ways to install fs-cdn.

npm install fs-cdn

or

git clone [email protected]:wotio/fs-cdn.git
cd fs-cdn
npm install

Next, create a file called config.json in your project. It should have a structure that conforms to the pkgcloud config object, which varies per provider. Below is an example of a config using Rackspace Cloudfiles:

{
	"data_dir" : "/path/to/data/dir" // required - the relative root directory, all paths will be relative to this
    "provider" : "rackspace",
    "username" : "<username>", // provider-specific, see pkgcloud's storage docs for supported providers and their respective config requirements
    "apiKey" : "<api key>",	// provider-specific
    "region" : "<region>", // optional
    "container" : "<container>" // optional, but without it you must specify the container per file operation
}

A sample script using fs-cdn would thus look something like this:

var Fs_Cdn = require('fs-cdn'),
remoteConfig = require('<path/to/remote/config.json>'),
localConfig = require('<path/to/local/config.json>');

var fs_cdn_remote = new Fs_Cdn(remoteConfig),
	fs_cdn_local = new Fs_Cdn(localConfig);

Available Methods

save(dest, source, options, callback)

Pipes ReadStream source to dest. If a string filepath is passed instead of a ReadStream, save creates a ReadStream from it.

dest: {string} Full path of destination file
source: {object or string} ReadStream or full path of source file
options: {object} Options object
callback: {function} Callback

var options = {
	persist: @boolean,	// If true, stores file in /perm subfolder. If false, stores files in /tmp 
	append: @boolean,	// If true, appends the source to the dest file, instead of overwriting
	compress: @boolean,	// If true, compresses the file using gzip.
	write: @boolean		// If true, looks for an instance of Buffer as argument[1] and writes it to the file.
}

fs_cdn_local.save('path/to/dest/filename.txt', <'path/to/src/filename.txt' or fs.createReadStream('path/to/src/filename.txt')>, options, function(err, result) {
	
	// result will be a file object like this:
	//		{
	//			size : @int,
	//			localpath : @string,
	//			name : @string,
	//			type : @string,
	//			encoding : 'binary'
	//		}

});

fs_cdn_remote.save('path/to/dest/filename.txt', <'path/to/src/filename.txt' or fs.createReadStream('path/to/src/filename.txt')>, options, function(err, result) {
	
	// result will be a file object like this:
	//		{
	//			size : @int,
	//			localpath : @string,
	//			name : @string,
	//			type : @string,
	//			container: @string,
	//			encoding : 'binary'
	//		}

});

get(source, callback)

Gets source and a readStream pointing to it. If a string filepath is passed instead of a File object, get normalizes it into a File object (after checking for its existence).

source: {object or string} Full path of source file or File object callback: {function} Callback

fs_cdn_local.get(<'path/to/src/filename.txt' or { localpath : 'path/to/src/filename.txt', name: 'filename.txt', encoding: 'binary' }>, function(err, result, readStream) {
	
	// result will be a file object like this:
	//		{
	//			size : @int,
	//			localpath : @string,
	//			name : @string,
	//			type : @string,
	//			container: @string,
	//			encoding : 'binary'
	//		}
	//
	// readStream will be an instance of fs.readStream from the filesystem

});

fs_cdn_remote.get(<'path/to/src/filename.txt' or { localpath : 'path/to/src/filename.txt', name: 'filename.txt', encoding: 'binary' }>, function(err, result, readStream) {
	
	// result will be a file object like this:
	//		{
	//			size : @int,
	//			localpath : @string,
	//			name : @string,
	//			type : @string,
	//			container: @string,
	//			encoding : 'binary'
	//		}
	//
	// readStream will be an instance of fs.readStream from the CDN storage provider

});

list(dir, callback) ->

Lists all files in dir or in remote container

dir: {string} directory path (local) or container name (remote, optional if container was specified in config)
callback: {function} Callback

fs_cdn_local.list('path/to/dst/dir', function(err, result) {
	// handle results
});
fs_cdn_remote.list(function(err, result) {
	// handle results
});

In the callback, result will be an array of the files in the container or folder.

find(file, callback) ->

Finds the specified file.

file: {string} directory path (local) or file name (remote)
callback: {function} Callback

fs_cdn_local.find('path/to/local/filename.txt', function(err, result) {
	// handle results
});

In the callback, results object will be an instance of fs.Stats

fs_cdn_remote.find('filename.txt', function(err, result) {
	// handle results
});

In the callback, result object will be a pkgcloud File Model.

remove(file, callback) ->

Removes the specified file.

file: {string} directory path (local) or file name (remote)
options: {object} Options object
callback: {function} Callback

fs_cdn_local.remove('path/to/local/filename.txt', function(err, result) {
	// handle results
});
fs_cdn_remote.remove('filename.txt', function(err, result) {
	// handle results
});

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2017 InterDigital, Inc. All Rights Reserved