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

crypto-fs

v0.8.0

Published

Wrapper around node fs module that encrypts the files on the fly

Downloads

39

Readme

crypto-fs

Wrapper around node fs module that encrypts the files on the fly

Code Climate Test Coverage Build Status Dependency Status devDependency Status

Installation

npm install crypto-fs --save

Requirements

Node.js 4+

Initialization

var fs = require('crypto-fs');
fs.init({
  baseFs: require('fs'),
  algorithm: 'aes-256-ctr',
  prefix: '',
  password: '1234',
  root: './test/dest',
  iv: null,
  realSize: false,
  dontEncPath : false
});

Options

  • baseFs (default: require("fs"))
    • What fs module should be used
  • algorithm (default: "aes-256-ctr")
    • Any algorithm supported by node.js crypto module.
  • prefix (default: "")
    • Encrypted filename prefix.
  • password (no default)
    • Please don't use 1234 as your password :)
  • root (no default)
    • Root directory of the encrypted files.
  • iv (default: null)
    • If initialization vector is given, Cipheriv will be used.
  • realSize (default: false)
    • Encrypted files have marginaly bigger file size than the normal sizes. To get the real file size, the file needs to be decrypted, so set this to true only if you need to.
  • dontEncPath (default: false)
    • If true, the filename will not be encrypted. Might solve issues of path in Windows.

Base FS

By default, this module relies on the native fs module, but this can be changed. If you have a different module that exposes the same methods (e.g. ftp-fs, s3-fs), you can set it as the base fs. For every exposed method, it will be documented which methods does it require from the base fs (except for the same method, readlink/readlinkSync and lstat/lstatSync). readlink/readlinkSync and lstat/lstatSync are used to determine if the given path is a symlink, and in this case follow the symlink.

If you're using the default fs module, you can ignore this info.

Implemented methods

  • init (non-standard)

    • used to initialize the module (documented above)
    • required baseFs methods: existsSync
  • readFile, readFileSync

  • writeFile, writeFileSync

  • exists, existsSync

  • access, accessSync

  • mkdir, mkdirSync

  • rmdir, rmdirSync

  • unlink, unlinkSync

  • stat, statSync

  • readdir ,readdirSync

  • readlink, readlinkSync

  • symlink, symlinkSync

  • lstat, lstatSync

  • rename

    • required: fs.readFile, fs.writeFile, fs.unlink
  • renameSync

    • required: fs.readFileSync, fs.writeFileSync, fs.unlinkSync
  • appendFile

    • required: access (or exists), readFile, writeFile
  • appendFileSync

    • required: accessSync (or existsSync), readFileSync, writeFileSync
  • createReadStream

  • createWriteStream

  • watchFile

  • unwatchFile

  • watch

Not tested

  • close, closeSync
  • fstat, fstatSync
  • futimes, futimesSync
  • fchown, fchownSync
  • fchmod, fchmodSync
  • utimes, utimesSync
  • chown, chownSync
  • chmod, chmodSync
  • lchown, lchownSync
  • lchmod, lchmodSync

Limitations / known issues

  • all paths should be relative to the root folder and they should be inside of the root folder
  • watch filename will be incorect if it's not in the root folder - should be possible to fix
  • rename and renameSync create a new file and remove the old so the watch might not behave as expected (would it be better to actually rename the file and write the new content?)
  • Renaming of folders isn't currently supported. You should create a new folder and move all the files in it.
  • symlinks only work if both the file and symlink are inside of the root folder
  • folder or symlink rename will probably corrupt the file - don't use it yet

Challenges

  • link and linkSync can't work because the filename would be wrong and therefore the file content couldn't be decrypted. Not yet sure if it's possible to solve this.

TODO

  • Add more tests based on https://github.com/nodejs/node/tree/master/test/parallel (fs & crypto)
  • More efficient appendFile
  • Support for relative & absolute paths
    • Use the base fs if outside of the root path
  • skip symlink check if baseFs doesn't suport either lstat or readlink
  • do normal rename if the file is a symlink
  • rename all files inside of a folder on folder rename
  • remove ./ from the file paths

Methods (Sync and async)

  • ftruncate

  • truncate

  • realpath

  • fsync

  • link

  • open

  • write

  • read

Attribution

  • Stream functionality based on node-efs
  • Internal "deep" readlink based on readlink