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

temp-fs

v0.9.9

Published

Temporary files, directories or names!

Downloads

1,297,951

Readme

temp-fs

Build Status NPM version

A temporary file and directory creator for io.js and Node.js™.

Just like raszi/node-tmp and bruce/node-temp, it can safely create temporary files and directories without worrying a lot of about race conditions as long as you don't do some tricky things. ;-) You can also let this module track the files or directories you created and delete them when the program exits.

Installation

npm install temp-fs
var tempfs = require('temp-fs');

// Create a tempfile in the system-provided tempdir.
tempfs.open(function (err, file) {
    if (err) { throw err; }

    console.log(file.path, file.fd);
    // async
    file.unlink(function () {
        console.log('File delected');
    });
    // sync
    // No problem even if unlink() is called twice.
    file.unlink();
});

// Create a tempdir in current directory.
tempfs.mkdir({
    dir: '.',
    recursive: true,  // It and its content will be remove recursively.
    track: true  // Track this directory.
}, function (err, dir) {
    if (err) { throw err; }

    console.log(dir.path, dir.recursive);
    throw new Error('Since it is tracked, tempfs will remove it for you.');
    dir.unlink();
});

APIs

options

  • limit: Number

    The maximum number of chance to retry before throwing an error. It should be a finite number. Default: 5

  • recursive: Boolean

    Whether unlink() should remove a directory recursively. Default: false

  • track: Boolean

    If set to true, let temp-fs manage the the current file/directory for you even if the global tracking is off. If set to false, don't let temp-fs manage it even if the global tracking is on. Otherwise, use the current global setting.

  • mode: Number

    File mode (default: 0600) or directory mode (default: 0700) to use.

  • name: String

    If set, join the two paths options.dir || tempfs.dir() and options.name together and use the result as the customized filename/pathname.

  • dir: String

    Where to put the generated tempfile or tempdir. Also see options.name above. Default: tempfs.dir()

  • prefix: String

    The prefix for the generated random name. Default: "tmp-"

  • suffix: String

    The suffix for the generated random name. Default: ""

  • template: String

    A string containing some capital letters Xs for substitution with random characters. Then it is used as part of the filename/dirname. Just like what you do with the mktemp (3) function in the C library.

tempfs.track(on = true)

Use it to switch global files/directories tracking on or off. Turn it on if you don't want to manually delete everything. When it is turned off, all recorded files and directories will not be removed but still kept in case it is turned on again before the program exits.

This switch does not affect manually tracked files through options.track. They will be removed automatically on exit.

Note: When an uncaught exception occurs, all tracked temporary files and directories will be removed no matter it is on or off.

tempfs.dir()

Return the path of a system-provided tempdir as require('os').tmpdir() does. You should not make any assumption about whether the path contains a trailing path separator, or it is a real path. On most system it is not a fixed path, and it can be changed by the user environment. When in doubt, check it first.

tempfs.name([options])

Return a customized/random filename/dirname. Options are documented at options.

tempfs.open([options], [callback])

Try to open a unique tempfile asynchronously. The callback function receives two arguments error and file. If error is null, file has these properties:

  • path: The absolute path to the tempfile.
  • fd: An integer file descriptor.
  • unlink: A special function for you to delete the file. If you invoke it with a callback function, it will become asynchronous. If the file is not tracked, it may throw when an error occurs or the first argument of the callback function will be an Error object.

tempfs.openSync([options]): file

The synchronous version of tempfs.open. It will throw when an error happens.

tempfs.mkdir([options], [callback])

Try to create a new tempdir asynchronously. The callback function receives two arguments error and dir. If error is null, dir has these properties:

  • path: The absolute path to the tempdir.
  • recursive: Whether unlink() will remove the tempdir recursively.
  • unlink: A special function for you to remove the directory. If you invoke it with a callback function, it will become asynchronous. If the directory is not tracked, it may throw when an error occurs or the first argument of the callback function will be an Error object.

tempfs.mkdirSync([options]): dir

The synchronous version of tempfs.mkdir. It will throw when an error happens.

tempfs.clear([callback])

Remove all tracked files and directories asynchronously.

tempfs.clearSync()

Remove all tracked files and directories synchronously.

License

The MIT License (MIT)