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

fs.js

v0.0.1

Published

A lightweight wrapper for File System API based on nodejs

Downloads

71

Readme

fs.js

This module provides a wrapper for the HTML5 File System API inspired in nodejs fs module. While the underlying HTML5 API is quite feature rich, it is low level and difficult to use.

fs.js provides a good tradeoff between easy to use and flexibility with a cleaner api.

Note that this module is inspired by node js, not a port, and will therefore not be totally compatible with it. Also the module provides some useful methods that only make sense on a browser environment (such as getting the url pointing to a local file).

Install

Just pick up fs.js and include it in a script tag or use it with an AMD compatible loader. If you want to run the unit tests you can install the module via npm:

    npm install fs.js
    

Unit tests

The unit tests are writte using mocha. For running the unit tests you need to use node and a webbrowser with File System API capabilities (only Chrome at the moment).

Go to the test directory and run the test server:

    node server.js
    

Open a webbrowser pointing to http://localhost:8080

Quick Start

Start by creating a file system. Note that we support a prefix for every file system. This prefix allows us to have several independent file systems:

    var sizeInBytes = 1024 * 1024,
      prefix = 'filetest';

    FSFactory.create(sizeInBytes, 'test_fs', function(err, fs) {
      fs.read('foo', function(err, data){
        // data contains file contents.
      });
    });

Check the methods section for all the methods provided by the file system object.

Methods

Renames a file or directory.

rename(oldPath, newPath, function(err))

Arguments

oldPath   {String} Old path.
newPath   {String} New path name.
callback  {Function} Callback called when finished.

Gives stats metadata of a file or directory

The received metadata in the callback contains the following properties: isFile, isDirectory, size, mtime (modification time)

stats(path, function(err, meta))

Arguments

path   {String} Path to file or directory.
callback {Function} Callback called when finished.

Checks if a file exists or not.

exists(path, function(err, exists))

Arguments

path   {String} Path to file or directory.
callback {Function} Callback called when finished.

Removes the given file from the filesystem.

remove(path, function(err))

unlink(path, function(err))

Arguments

path     {String} Path to file.
callback {Function} Callback called when finished.

Removes the dir at the given path (and all its contents including subdirs and files).

rmdir(path, function(err))

Arguments

path     {String} Path to directory.
callback {Function} Callback called when finished.

Makes a directory in the given path.

mkdir(path, function(err, direntry))

Arguments

path     {String} Path to directory.
callback {Function} Callback called when finished.

Makes a directory and all the subdirectories (if needed) to the given path.

mkpath(path, function(err, direntry))

Arguments

path     {String} Path to directory.
callback {Function} Callback called when finished.

Reads the contents of a directory at the given path.

readdir(path, function(err, entries))

Arguments

path     {String} Path to directory.
callback {Function} Callback called when finished.

Reads the content of a file specified at the given path. The contents of the file are returned as binary data (ArrayBuffer), or as text depending on the selected encoding.

readFile(path, encoding, function(err, data))

Arguments

path     {String} Path to a file.
encoding [{String}] Optional encoding (such as 'UTF-8'), otherwise returns data as
an ArrayBuffer.
callback {Function} Callback called when finished.

Reads the content of a file specified at the given path as a Blob.

readFileAsBlob(path, function(err, blob))

Arguments

path     {String} Path to a file.
callback {Function} Callback called when finished.

Reads the content of a file specified at the given path as a URL. This function is useful for setting local binary files as images, videos, sounds, fonts, etc.

readFileAsUrl(path, function(err, url))

Arguments

path     {String} Path to a file.
callback {Function} Callback called when finished.

Writes a string, Blob or ArrayBuffer data to a file.

writeFile(path, data, function(err))

Arguments

path     {String} Path to a file.
data     {String|Blob|ArrayBuffer} Data to write to the file.
callback {Function} Callback called when finished.

Appends a string, Blob or ArrayBuffer to a file.

appendFile(path, data, function(err))

Arguments

path     {String} Path to a file.
data     {String|Blob|ArrayBuffer} Data to append to the file.
callback {Function} Callback called when finished.

Wipes the whole file system.

Use full = true if you want to wipe the root dir of the filesystem, after doing this, the instance cannot be used anymore.

wipe(function(), [full])

Arguments

callback {Function} Callback called when finished.
full     {Boolean} true if all filesystems should be removed.