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

@nfi/safeish-tmp

v2.1.1

Published

Simplified creation, scrubbing and deletion of temporary files.

Downloads

12

Readme

@nfi/safeish-tmp

npm version pipeline status coverage status standard-js

Simplified creation, scrubbing and deletion of temporary files.

Installation

npm install @nfi/safeish-tmp

Documentation

API documentation is available here.

Example

Standard form, using open/openSync:

const safeish = require('@nfi/safeish-tmp')
const child = require('child_process')
const util = require('util')
const execP = util.promisify(child.exec)

async function wrapperFunction(inData) {
  // create two temp files with randomised paths
  const inFile = await safeish.open()
  const outFile = await safeish.open()
  try {
    // prepare one file with input data
    await inFile.write(inData)
    // pass file paths to poorly built command-line utility that
    // didn't allow you to do what you needed using stdin/stdout
    await execP('/usr/bin/im_the_reason_this_package_exists', [
      '--input', inFile.path,
      '--output', outFile.path
    ])
    // retrieve output data from the second file
    return await outFile.readAll()
  } finally {
    // close, scrub and delete both files when finished
    await inFile.close()
    await outFile.close()
  }
}

Alternative form, using guard/guardSync:

const safeish = require('@nfi/safeish-tmp')
const child = require('child_process')
const util = require('util')
const execP = util.promisify(child.exec)

async function wrapperFunction(inData) {
  // create two temp files with randomised paths
  return safeish.guard(async (inFile) => {
    return safeish.guard(async (outFile) => {
      // prepare one file with input data
      await inFile.write(inData)
      // pass file paths to poorly built command-line utility that
      // didn't allow you to do what you needed using stdin/stdout
      await execP('/usr/bin/im_the_reason_this_package_exists', [
        '--input', inFile.path,
        '--output', outFile.path
      ])
      // retrieve output data from the second file; this value will
      // be passed back through the calls to guard()
      return await outFile.readAll()
    })
  })
  // both files are automatically closed, scrubbed and deleted
  // once the callback (or its returned promise) completes
}

Catch-all cleanup on exit:

const safeish = require('@nfi/safeish-tmp')

// close, scrub and delete any remaining open files
process.on('exit', safeish.closeAllSync)