Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fsu

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fsu

Unique file name with streams support

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
779K
decreased by-42.69%
Maintainers
1
Weekly downloads
 
Created
Source

#fsu (fs unique) Unique filenames with streams support

Checking if a file exists before opening is an anti-pattern that leaves you vulnerable to race conditions: another process can remove the file between the calls to fs.exists() and fs.open(). This functions doesn't use fs.exists functionality. If file doesn't exist this will work like usual fs module methods

##Instalation npm install fsu

openUnique(path, [mode], callback)

Same as fs.open but open for writing and creates unique filename.

var fsu = require('fsu');

fsu.openUnique("text{_###}.txt", function(err, fd) {
    //now we can use file descriptor as usual
});

writeFileUnique(path, data, [options], callback)

Same as fs.writeFile but creates unique filename.

var fsu = require('fsu');

fsu.writeFileUnique("text{_###}.txt", "test", function(err) {
    console.log("Done");
});

createUniqueWriteStream(path, [options])

Same as fs.createReadStream but returns writable stream for unique file.

var fsu = require('fsu');
var stream = fsu.createUniqueWriteStream("text{_###}.txt");

pattern

You must use {#} pattern in filename and path. All # characters will be change with counter for existing files. Number of # means padding for unique counter

If we run second example several times filenames will be

text.txt
text_001.txt
text_002.txt

License: MIT

Keywords

FAQs

Package last updated on 06 Apr 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc