Comparing version 1.0.3 to 1.0.4
37
index.js
@@ -12,3 +12,3 @@ 'use strict'; | ||
let padNum = function(n, width, z) { | ||
const padNum = function(n, width, z) { | ||
z = z || '0'; | ||
@@ -19,3 +19,3 @@ n = n + ''; | ||
let writeAll = function(fd, buffer, offset, length, position, cb) { | ||
const writeAll = function(fd, buffer, offset, length, position, cb) { | ||
fs.write(fd, buffer, offset, length, position, (writeErr, written) => { | ||
@@ -35,3 +35,3 @@ if (writeErr) { | ||
let mkdirp = function(p, mode, cb) { | ||
const mkdirp = function(p, mode, cb) { | ||
fs.mkdir(p, mode, err => { | ||
@@ -56,5 +56,5 @@ if (!err) { | ||
let openUniqueHandler = function(tryNum, fileParts, options, cb) { | ||
let file = options.simple ? fileParts.tail : tryNum ? (fileParts.head + fileParts.padLeft + padNum(tryNum, fileParts.pad) + fileParts.padRight + fileParts.tail) : (fileParts.head + fileParts.tail); | ||
let newPath = path.join(fileParts.path, file); | ||
const openUniqueHandler = function(tryNum, fileParts, options, cb) { | ||
const file = options.simple ? fileParts.tail : tryNum ? (fileParts.head + fileParts.padLeft + padNum(tryNum, fileParts.pad) + fileParts.padRight + fileParts.tail) : (fileParts.head + fileParts.tail); | ||
const newPath = path.join(fileParts.path, file); | ||
@@ -78,8 +78,8 @@ fs.open(newPath, options.flags || 'w', options.mode || defaultFileMode, (err, fd) => { | ||
let openUnique = function(file, options, cb) { | ||
const openUnique = function(file, options, cb) { | ||
file = path.resolve(file); | ||
let filePath = path.dirname(file); | ||
let fileName = path.basename(file); | ||
const filePath = path.dirname(file); | ||
const fileName = path.basename(file); | ||
let fileParts = rxFileParts.exec(fileName); | ||
const fileParts = rxFileParts.exec(fileName); | ||
@@ -106,3 +106,3 @@ if (!fileParts) { | ||
let writeFileUnique = function(filename, data, options, cb) { | ||
const writeFileUnique = function(filename, data, options, cb) { | ||
if (cb === undefined) { | ||
@@ -121,5 +121,5 @@ cb = options; | ||
} else { | ||
let buffer = Buffer.isBuffer(data) ? data : new Buffer('' + data, options.encoding || 'utf8'); | ||
const buffer = Buffer.isBuffer(data) ? data : new Buffer('' + data, options.encoding || 'utf8'); | ||
writeAll(fd, buffer, 0, buffer.length, 0, function() { | ||
let args = Array.prototype.slice.call(arguments); | ||
const args = Array.prototype.slice.call(arguments); | ||
cb.apply(null, args.concat(newPath)); | ||
@@ -132,3 +132,3 @@ }); | ||
// stream | ||
let WriteStreamUnique = function(file, options) { | ||
const WriteStreamUnique = function(file, options) { | ||
if (options && options.force) { | ||
@@ -159,3 +159,3 @@ this.force = options.force; | ||
let createWriteStreamUnique = function(file, options) { | ||
const createWriteStreamUnique = function(file, options) { | ||
return new WriteStreamUnique(file, options); | ||
@@ -165,5 +165,6 @@ }; | ||
module.exports = { | ||
openUnique: openUnique, | ||
writeFileUnique: writeFileUnique, | ||
createWriteStreamUnique: createWriteStreamUnique | ||
openUnique, | ||
writeFileUnique, | ||
WriteStreamUnique, | ||
createWriteStreamUnique | ||
}; |
@@ -27,3 +27,3 @@ { | ||
}, | ||
"version": "1.0.3" | ||
"version": "1.0.4" | ||
} |
# fsu (fs unique) | ||
[![NPM Version](https://img.shields.io/npm/v/fsu.svg?style=flat-square)](https://www.npmjs.com/package/fsu) | ||
[![NPM Downloads](https://img.shields.io/npm/dt/fsu.svg?style=flat-square)](https://www.npmjs.com/package/fsu) | ||
Unique filenames with streams support | ||
@@ -3,0 +7,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8466
154
61