fs-blob-storage
Advanced tools
Comparing version 1.3.0 to 2.0.0
# Changelog | ||
## v2.0.0 2019-05-07 | ||
* Breaking change: dropped support for Node 8. | ||
## v1.3.0 2018-10-22 | ||
@@ -4,0 +8,0 @@ |
@@ -23,50 +23,45 @@ "use strict"; | ||
} | ||
createWriteStream(key, options = {}) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const { ext = this.ext, part = this.part, encoding } = options; | ||
const filepath = path_1.default.join(this.path, key + ext); | ||
const dirpath = path_1.default.dirname(filepath); | ||
yield this.fsPromises.mkdir(dirpath, { recursive: true }); | ||
// for exclusive mode it will reject if file already exist | ||
const fd = yield this.fsPromises.open(filepath, this.writeFlags); | ||
if (part) { | ||
// do `open` instead of `stat` to prevent race condition | ||
const fdPart = yield this.fsPromises.open(filepath + part, this.writeFlags); | ||
// `close` before `rename` just for Windows | ||
yield this.fsPromises.close(fdPart); | ||
// `rename` overwrites quietly the file | ||
yield this.fsPromises.rename(filepath, filepath + part); | ||
} | ||
// first argument is ignored | ||
return this.fs.createWriteStream(filepath + part, { fd, encoding }); | ||
}); | ||
async createWriteStream(key, options = {}) { | ||
const { ext = this.ext, part = this.part, encoding } = options; | ||
const filepath = path_1.default.join(this.path, key + ext); | ||
const dirpath = path_1.default.dirname(filepath); | ||
await this.fsPromises.mkdir(dirpath, { recursive: true }); | ||
// for exclusive mode it will reject if file already exist | ||
const fd = await this.fsPromises.open(filepath, this.writeFlags); | ||
if (part) { | ||
// do `open` instead of `stat` to prevent race condition | ||
const fdPart = await this.fsPromises.open(filepath + part, this.writeFlags); | ||
// `close` before `rename` just for Windows | ||
await this.fsPromises.close(fdPart); | ||
// `rename` overwrites quietly the file | ||
await this.fsPromises.rename(filepath, filepath + part); | ||
} | ||
// first argument is ignored | ||
return this.fs.createWriteStream(filepath + part, { fd, encoding }); | ||
} | ||
createReadStream(key, options = {}) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const { ext = this.ext, encoding } = options; | ||
async createReadStream(key, options = {}) { | ||
const { ext = this.ext, encoding } = options; | ||
const filepath = path_1.default.join(this.path, key + ext); | ||
const fd = await this.fsPromises.open(filepath, 'r'); | ||
const stats = await this.fsPromises.stat(filepath); | ||
if (!stats.size) { | ||
throw Object.assign(new Error(`ENOENT: empty file, open '${filepath}'`), { | ||
code: 'ENOENT', | ||
path: filepath, | ||
}); | ||
} | ||
return this.fs.createReadStream(filepath, { fd, encoding }); | ||
} | ||
async commit(key, options = {}) { | ||
const { ext = this.ext, part = this.part } = options; | ||
if (part) { | ||
const filepath = path_1.default.join(this.path, key + ext); | ||
const fd = yield this.fsPromises.open(filepath, 'r'); | ||
const stats = yield this.fsPromises.stat(filepath); | ||
if (!stats.size) { | ||
throw Object.assign(new Error(`ENOENT: empty file, open '${filepath}'`), { code: 'ENOENT', path: filepath }); | ||
} | ||
return this.fs.createReadStream(filepath, { fd, encoding }); | ||
}); | ||
return this.fsPromises.rename(filepath + part, filepath); | ||
} | ||
} | ||
commit(key, options = {}) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const { ext = this.ext, part = this.part } = options; | ||
if (part) { | ||
const filepath = path_1.default.join(this.path, key + ext); | ||
return this.fsPromises.rename(filepath + part, filepath); | ||
} | ||
}); | ||
async remove(key, options = {}) { | ||
const { ext = this.ext } = options; | ||
const filepath = path_1.default.join(this.path, key + ext); | ||
return this.fsPromises.unlink(filepath); | ||
} | ||
remove(key, options = {}) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const { ext = this.ext } = options; | ||
const filepath = path_1.default.join(this.path, key + ext); | ||
return this.fsPromises.unlink(filepath); | ||
}); | ||
} | ||
} | ||
@@ -73,0 +68,0 @@ FsBlobStorage.DEFAULT_EXT = ''; |
{ | ||
"name": "fs-blob-storage", | ||
"version": "1.3.0", | ||
"version": "2.0.0", | ||
"description": "Blob storage on filesystem, with streams and promises API", | ||
@@ -32,29 +32,27 @@ "main": "lib/fs-blob-storage.js", | ||
"devDependencies": { | ||
"@types/chai": "^4.1.6", | ||
"@types/chai": "^4.1.7", | ||
"@types/chai-as-promised": "^7.1.0", | ||
"@types/make-dir": "^1.0.3", | ||
"@types/mocha": "^5.2.5", | ||
"@types/node": "^10.12.0", | ||
"@types/mocha": "^5.2.6", | ||
"@types/node": "^12.0.0", | ||
"chai": "^4.2.0", | ||
"chai-as-promised": "^7.1.1", | ||
"coveralls": "^3.0.2", | ||
"eslint": "^5.7.0", | ||
"eslint-config-standard": "^12.0.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint-plugin-node": "^7.0.1", | ||
"eslint-plugin-promise": "^4.0.1", | ||
"eslint-plugin-standard": "^4.0.0", | ||
"make-dir": "^1.3.0", | ||
"markdownlint-cli": "^0.13.0", | ||
"mocha": "^5.2.0", | ||
"nyc": "^13.1.0", | ||
"coveralls": "^3.0.3", | ||
"eslint": "^5.16.0", | ||
"eslint-config-prettier": "^4.2.0", | ||
"eslint-plugin-import": "^2.17.2", | ||
"eslint-plugin-node": "^9.0.1", | ||
"eslint-plugin-promise": "^4.1.1", | ||
"make-dir": "^3.0.0", | ||
"markdownlint-cli": "^0.15.0", | ||
"mocha": "^6.1.4", | ||
"nyc": "^14.1.0", | ||
"prettier": "^1.17.0", | ||
"promise-readable": "^3.1.5", | ||
"promise-writable": "^3.1.2", | ||
"rimraf": "^2.6.2", | ||
"rimraf": "^2.6.3", | ||
"stream.pipeline-shim": "^1.0.4", | ||
"ts-node": "^7.0.1", | ||
"tslint": "^5.11.0", | ||
"tslint-config-standard": "^8.0.1", | ||
"tslint-eslint-rules": "^5.4.0", | ||
"typescript": "^3.1.3" | ||
"ts-node": "^8.1.0", | ||
"tslint": "^5.16.0", | ||
"tslint-config-prettier": "^1.18.0", | ||
"typescript": "^3.4.5" | ||
}, | ||
@@ -66,3 +64,3 @@ "scripts": { | ||
"prepublishOnly": "npm run build", | ||
"pretest": "npm run build && tsc --pretty -p examples && tsc --pretty -p test && eslint . && tslint -t stylish -p . && tslint -t stylish -p examples && tslint -t stylish -p test && markdownlint \"*.md\"", | ||
"pretest": "npm run build && tsc --pretty -p examples && tsc --pretty -p test && eslint . && tslint -t stylish -p . && tslint -t stylish -p examples && tslint -t stylish -p test && prettier --ignore-path .gitignore --list-different '**/*.ts' '**/*.js' && markdownlint \"*.md\"", | ||
"test": "npm run test:spec", | ||
@@ -69,0 +67,0 @@ "test:spec": "npm run ts-mocha -- \"test/*.ts\"", |
@@ -20,3 +20,3 @@ # fs-blob-storage | ||
This module requires Node >= 6. | ||
This module requires Node >= 8. | ||
@@ -166,4 +166,4 @@ ## Installation | ||
Copyright (c) 2018 Piotr Roszatycki <piotr.roszatycki@gmail.com> | ||
Copyright (c) 2018-2019 Piotr Roszatycki <piotr.roszatycki@gmail.com> | ||
[MIT](https://opensource.org/licenses/MIT) |
@@ -40,7 +40,7 @@ /// <reference types="node" /> | ||
interface FsPromises { | ||
close: typeof fs.close.__promisify__, | ||
mkdir: typeof fs.mkdir.__promisify__, | ||
open: typeof fs.open.__promisify__, | ||
rename: typeof fs.rename.__promisify__, | ||
stat: typeof fs.stat.__promisify__, | ||
close: typeof fs.close.__promisify__ | ||
mkdir: typeof fs.mkdir.__promisify__ | ||
open: typeof fs.open.__promisify__ | ||
rename: typeof fs.rename.__promisify__ | ||
stat: typeof fs.stat.__promisify__ | ||
unlink: typeof fs.unlink.__promisify__ | ||
@@ -61,3 +61,3 @@ } | ||
constructor (options: FsBlobStorageOptions = {}) { | ||
constructor(options: FsBlobStorageOptions = {}) { | ||
this.ext = options.ext !== undefined ? options.ext : FsBlobStorage.DEFAULT_EXT | ||
@@ -76,8 +76,8 @@ this.part = options.part !== undefined ? options.part : FsBlobStorage.DEFAULT_PART | ||
async createWriteStream (key: string, options: FsBlobStorageWriteStreamOptions = {}): Promise<fs.WriteStream> { | ||
const { ext = this.ext, part = this.part, encoding } = options | ||
async createWriteStream(key: string, options: FsBlobStorageWriteStreamOptions = {}): Promise<fs.WriteStream> { | ||
const {ext = this.ext, part = this.part, encoding} = options | ||
const filepath = path.join(this.path, key + ext) | ||
const dirpath = path.dirname(filepath) | ||
await this.fsPromises.mkdir(dirpath, { recursive: true }) | ||
await this.fsPromises.mkdir(dirpath, {recursive: true}) | ||
@@ -99,7 +99,7 @@ // for exclusive mode it will reject if file already exist | ||
// first argument is ignored | ||
return this.fs.createWriteStream(filepath + part, { fd, encoding }) | ||
return this.fs.createWriteStream(filepath + part, {fd, encoding}) | ||
} | ||
async createReadStream (key: string, options: FsBlobStorageReadStreamOptions = {}): Promise<fs.ReadStream> { | ||
const { ext = this.ext, encoding } = options | ||
async createReadStream(key: string, options: FsBlobStorageReadStreamOptions = {}): Promise<fs.ReadStream> { | ||
const {ext = this.ext, encoding} = options | ||
const filepath = path.join(this.path, key + ext) | ||
@@ -112,10 +112,13 @@ | ||
if (!stats.size) { | ||
throw Object.assign(new Error(`ENOENT: empty file, open '${filepath}'`), { code: 'ENOENT', path: filepath }) | ||
throw Object.assign(new Error(`ENOENT: empty file, open '${filepath}'`), { | ||
code: 'ENOENT', | ||
path: filepath, | ||
}) | ||
} | ||
return this.fs.createReadStream(filepath, { fd, encoding }) | ||
return this.fs.createReadStream(filepath, {fd, encoding}) | ||
} | ||
async commit (key: string, options: FsBlobStorageCommitOptions = {}): Promise<void> { | ||
const { ext = this.ext, part = this.part } = options | ||
async commit(key: string, options: FsBlobStorageCommitOptions = {}): Promise<void> { | ||
const {ext = this.ext, part = this.part} = options | ||
if (part) { | ||
@@ -127,4 +130,4 @@ const filepath = path.join(this.path, key + ext) | ||
async remove (key: string, options: FsBlobStorageRemoveOptions = {}): Promise<void> { | ||
const { ext = this.ext } = options | ||
async remove(key: string, options: FsBlobStorageRemoveOptions = {}): Promise<void> { | ||
const {ext = this.ext} = options | ||
const filepath = path.join(this.path, key + ext) | ||
@@ -131,0 +134,0 @@ return this.fsPromises.unlink(filepath) |
@@ -6,5 +6,3 @@ { | ||
"importHelpers": true, | ||
"lib": [ | ||
"es6" | ||
], | ||
"lib": ["es2017"], | ||
"module": "commonjs", | ||
@@ -16,13 +14,7 @@ "noImplicitAny": true, | ||
"outDir": "./lib", | ||
"target": "es6", | ||
"target": "es2017", | ||
"strict": true, | ||
"typeRoots": [ | ||
"node_modules/@types" | ||
] | ||
"typeRoots": ["node_modules/@types"] | ||
}, | ||
"exclude": [ | ||
"./examples/**/*", | ||
"./lib/**/*", | ||
"./test/**/*" | ||
] | ||
"exclude": ["./examples/**/*", "./lib/**/*", "./test/**/*"] | ||
} |
Sorry, the diff of this file is not supported yet
25
18295
242