fs-blob-storage
Advanced tools
Comparing version 2.1.0 to 2.1.1
# Changelog | ||
## v2.1.1 2019-06-04 | ||
- Minor tweaks in README. | ||
- Added source map to the package. | ||
## v2.1.0 2019-05-15 | ||
* Does not use `util.promisify` package. | ||
- Does not use `util.promisify` package. | ||
## v2.0.2 2019-05-15 | ||
* Use `@types/util.promisify` package. | ||
- Use `@types/util.promisify` package. | ||
## v2.0.1 2019-05-08 | ||
* Fix dependencies. | ||
- Fix dependencies. | ||
## v2.0.0 2019-05-07 | ||
* Breaking change: dropped support for Node 8. | ||
- Breaking change: dropped support for Node 8. | ||
## v1.3.0 2018-10-22 | ||
* Uses `fs.mkdir-shim` instead `make-dir`. It will use native `fs.mkdir` with | ||
- Uses `fs.mkdir-shim` instead `make-dir`. It will use native `fs.mkdir` with | ||
`recursive` option on Node >= 10.12. | ||
@@ -26,3 +31,3 @@ | ||
* `DEFAULT_EXT` and `DEFAULT_PART` are static readonly properties of | ||
- `DEFAULT_EXT` and `DEFAULT_PART` are static readonly properties of | ||
`FsBlobStorage` class. | ||
@@ -32,3 +37,3 @@ | ||
* The `defaultExt` and `defaultPart` options has need renamed to `ext` and | ||
- The `defaultExt` and `defaultPart` options has need renamed to `ext` and | ||
`part`. | ||
@@ -38,34 +43,34 @@ | ||
* Rewritten in Typescript. | ||
* New syntax of import in plain Javascript. | ||
- Rewritten in Typescript. | ||
- New syntax of import in plain Javascript. | ||
## v0.6.1 2018-07-16 | ||
* Pack only important files. | ||
- Pack only important files. | ||
## v0.6.0 2018-07-16 | ||
* New option `fs` with File System module. | ||
* Tests don't use `mock-fs` package anymore. | ||
* Tweaked jsdoc. | ||
- New option `fs` with File System module. | ||
- Tests don't use `mock-fs` package anymore. | ||
- Tweaked jsdoc. | ||
## v0.5.2 2018-05-24 | ||
* Uses `stream.pipeline-shim` package for examples. | ||
- Uses `stream.pipeline-shim` package for examples. | ||
## v0.5.1 2018-05-24 | ||
* Call `close` before `rename` to make storage compatible with Windows. | ||
- Call `close` before `rename` to make storage compatible with Windows. | ||
## v0.5.0 2018-05-19 | ||
* New constructor option `defaultExt` and `defaultPart`. | ||
- New constructor option `defaultExt` and `defaultPart`. | ||
## v0.4.1 2018-05-18 | ||
* Uses `stream.pipeline` shim instead `pump` in example scripts. | ||
- Uses `stream.pipeline` shim instead `pump` in example scripts. | ||
## v0.4.0 2018-05-15 | ||
* Breaking change: `encoding` is `null` by default and then storage object | ||
- Breaking change: `encoding` is `null` by default and then storage object | ||
returns `Buffer`. | ||
@@ -75,15 +80,15 @@ | ||
* Typescript: return fs.WriteStream or fs.ReadStream. | ||
- Typescript: return fs.WriteStream or fs.ReadStream. | ||
## v0.2.1 2018-05-13 | ||
* Bugfix: write to .part file if `part` option is set. | ||
- Bugfix: write to .part file if `part` option is set. | ||
## v0.2.0 2018-05-10 | ||
* Builds with Node 10. | ||
* Uses `util.promisify` instead of `mz`. | ||
- Builds with Node 10. | ||
- Uses `util.promisify` instead of `mz`. | ||
## v0.1.0 2018-05-06 | ||
* Initial release | ||
- Initial release |
@@ -1,1 +0,1 @@ | ||
module.exports = require('./lib/fs-blob-storage') | ||
module.exports = require("./lib/fs-blob-storage") |
/// <reference types="node" /> | ||
import fs from 'fs'; | ||
import fs from "fs"; | ||
export interface FsBlobStorageOptions { | ||
@@ -4,0 +4,0 @@ ext?: string; |
@@ -13,8 +13,8 @@ "use strict"; | ||
this.part = options.part !== undefined ? options.part : FsBlobStorage.DEFAULT_PART; | ||
this.writeFlags = options.exclusive ? 'wx' : 'w'; | ||
this.writeFlags = options.exclusive ? "wx" : "w"; | ||
this.fs = options.fs || fs_1.default; | ||
this.path = options.path || '.'; | ||
this.path = options.path || "."; | ||
this.fsPromises = {}; | ||
this.fsPromises.mkdir = util_1.default.promisify(fs_mkdir_shim_1.default); | ||
for (const method of ['close', 'open', 'rename', 'stat', 'unlink']) { | ||
for (const method of ["close", "open", "rename", "stat", "unlink"]) { | ||
this.fsPromises[method] = util_1.default.promisify(this.fs[method]); | ||
@@ -44,7 +44,7 @@ } | ||
const filepath = path_1.default.join(this.path, key + ext); | ||
const fd = await this.fsPromises.open(filepath, 'r'); | ||
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', | ||
code: "ENOENT", | ||
path: filepath, | ||
@@ -68,5 +68,6 @@ }); | ||
} | ||
FsBlobStorage.DEFAULT_EXT = ''; | ||
FsBlobStorage.DEFAULT_PART = '.part'; | ||
FsBlobStorage.DEFAULT_EXT = ""; | ||
FsBlobStorage.DEFAULT_PART = ".part"; | ||
exports.FsBlobStorage = FsBlobStorage; | ||
exports.default = FsBlobStorage; | ||
//# sourceMappingURL=fs-blob-storage.js.map |
{ | ||
"name": "fs-blob-storage", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "Blob storage on filesystem, with streams and promises API", | ||
@@ -32,12 +32,12 @@ "main": "lib/fs-blob-storage.js", | ||
"@types/chai": "^4.1.7", | ||
"@types/chai-as-promised": "^7.1.0", | ||
"@types/mocha": "^5.2.6", | ||
"@types/node": "^12.0.2", | ||
"@types/dirty-chai": "^2.0.0", | ||
"@types/mocha": "^5.2.7", | ||
"@types/node": "^12.0.4", | ||
"chai": "^4.2.0", | ||
"chai-as-promised": "^7.1.1", | ||
"coveralls": "^3.0.3", | ||
"dirty-chai": "^2.0.1", | ||
"eslint": "^5.16.0", | ||
"eslint-config-prettier": "^4.2.0", | ||
"eslint-plugin-import": "^2.17.2", | ||
"eslint-plugin-node": "^9.0.1", | ||
"eslint-config-prettier": "^4.3.0", | ||
"eslint-plugin-import": "^2.17.3", | ||
"eslint-plugin-node": "^9.1.0", | ||
"eslint-plugin-promise": "^4.1.1", | ||
@@ -49,32 +49,26 @@ "make-dir": "^3.0.0", | ||
"prettier": "^1.17.1", | ||
"promise-readable": "^4.2.0", | ||
"promise-writable": "^4.1.0", | ||
"promise-readable": "^4.2.1", | ||
"promise-writable": "^4.1.1", | ||
"shx": "^0.3.2", | ||
"stream.pipeline-shim": "^1.1.0", | ||
"ts-node": "^8.1.0", | ||
"tslint": "^5.16.0", | ||
"ts-node": "^8.2.0", | ||
"tslint": "^5.17.0", | ||
"tslint-config-prettier": "^1.18.0", | ||
"typescript": "^3.4.5" | ||
"typescript": "^3.5.1" | ||
}, | ||
"scripts": { | ||
"build": "npm run compile", | ||
"compile": "tsc --pretty", | ||
"clean": "shx rm -rf lib", | ||
"compile": "tsc --pretty --project .", | ||
"clean": "npm run clean:compile && npm run clean:coverage", | ||
"clean:compile": "shx rm -rf lib", | ||
"clean:coverage": "shx rm -rf coverage .nyc_output", | ||
"lint": "npm run compile && 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 '**/*.{js,json,md,ts,yml}' && markdownlint \"*.md\"", | ||
"postpublish": "git tag v$npm_package_version -a -m \"Release v$npm_package_version\" && git push --tags", | ||
"prepack": "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 && prettier --ignore-path .gitignore --list-different '**/*.js' '**/*.json' '**/*.ts' '**/*.yml' && markdownlint \"*.md\"", | ||
"prepack": "npm run compile", | ||
"prepublishOnly": "npm run test", | ||
"pretest": "npm run lint", | ||
"test": "npm run test:spec", | ||
"test:spec": "npm run ts-mocha -- \"test/*.ts\"", | ||
"test:coverage": "nyc --reporter json npm run test:spec && nyc report", | ||
"ts-mocha": "mocha --use_strict --throw-deprecation --require source-map-support/register --require ts-node/register --timeout 90000" | ||
}, | ||
"nyc": { | ||
"extension": [ | ||
".ts" | ||
], | ||
"exclude": [ | ||
".*.js", | ||
"**/*.d.ts" | ||
] | ||
"test:coverage": "npm run clean:coverage && cross-env NYC=\"nyc --no-clean --reporter=lcov\" npm run test:spec && nyc report --reporter=text-summary --color", | ||
"ts-mocha": "$NYC mocha --use_strict --throw-deprecation --require source-map-support/register --require ts-node/register --timeout 90000" | ||
} | ||
} |
# fs-blob-storage | ||
<!-- markdownlint-disable MD013 --> | ||
[![Build Status](https://secure.travis-ci.org/dex4er/js-fs-blob-storage.svg)](http://travis-ci.org/dex4er/js-fs-blob-storage) [![Coverage Status](https://coveralls.io/repos/github/dex4er/js-fs-blob-storage/badge.svg)](https://coveralls.io/github/dex4er/js-fs-blob-storage) [![npm](https://img.shields.io/npm/v/fs-blob-storage.svg)](https://www.npmjs.com/package/fs-blob-storage) | ||
<!-- markdownlint-enable MD013 --> | ||
@@ -11,8 +13,8 @@ | ||
* Simple API | ||
* Read and write file streams | ||
* Partial files | ||
* Safe, atomic operations | ||
* Works with any POSIX or NTFS filesystem | ||
* NFS friendly locking | ||
- Simple API | ||
- Read and write file streams | ||
- Partial files | ||
- Safe, atomic operations | ||
- Works with any POSIX or NTFS filesystem | ||
- NFS friendly locking | ||
@@ -35,18 +37,6 @@ ## Requirements | ||
Transpiling this module with own settings in `tsconfig.json`: | ||
```json | ||
{ | ||
"compilerOptions": { | ||
"paths": { | ||
"fs-blob-storage": ["node_modules/fs-blob-storage/src/fs-blob-storage"] | ||
} | ||
} | ||
} | ||
``` | ||
## Usage | ||
```js | ||
const {FsBlobStorage} = require('fs-blob-storage') | ||
const {FsBlobStorage} = require("fs-blob-storage") | ||
``` | ||
@@ -57,3 +47,5 @@ | ||
```ts | ||
import {FsBlobStorage} from 'fs-blob-storage' | ||
import FsBlobStorage from "fs-blob-storage" | ||
// or | ||
import {FsBlobStorage} from "fs-blob-storage" | ||
``` | ||
@@ -77,11 +69,11 @@ | ||
* `ext` is a default `ext` argument for methods (optional, default: | ||
- `ext` is a default `ext` argument for methods (optional, default: | ||
`DEFAULT_EXT`) | ||
* `part` is a default `part` argument for methods (optional, default: | ||
- `part` is a default `part` argument for methods (optional, default: | ||
`DEFAULT_PART`) | ||
* `exclusive` if is true then can't create new object if already exists with | ||
- `exclusive` if is true then can't create new object if already exists with | ||
the same key (optional, default: `false`) | ||
* `fs` is a [File System](https://nodejs.org/api/fs.html) module (optional, | ||
- `fs` is a [File System](https://nodejs.org/api/fs.html) module (optional, | ||
default: `require('fs')`) | ||
* `path` is a directory path of the storage (optional, default: `'.'`) | ||
- `path` is a directory path of the storage (optional, default: `'.'`) | ||
@@ -92,5 +84,5 @@ _Example:_ | ||
const storage = new FsBlobStorage({ | ||
part: '.lock', | ||
path: '/var/spool/mail', | ||
exclusive: true | ||
part: ".lock", | ||
path: "/var/spool/mail", | ||
exclusive: true, | ||
}) | ||
@@ -107,7 +99,7 @@ ``` | ||
* `ext` is a default extension added to file name for the object (optional, | ||
default: `this.ext`) | ||
* `part` is a extension added to file name which can be later commited | ||
(optional, default: `this.part`) | ||
* `encoding` is a encoding for created file (optional, default: `null`) | ||
- `ext` is a default extension added to file name for the object (optional, | ||
default: `this.ext`) | ||
- `part` is a extension added to file name which can be later commited | ||
(optional, default: `this.part`) | ||
- `encoding` is a encoding for created file (optional, default: `null`) | ||
@@ -126,5 +118,5 @@ Creates a writable stream for a new object in the storage. Object is stored with | ||
* `ext` is a default extension added to file name for the object (optional, | ||
default: '') | ||
* `encoding` is a encoding for created file (optional, default: 'utf8') | ||
- `ext` is a default extension added to file name for the object (optional, | ||
default: '') | ||
- `encoding` is a encoding for created file (optional, default: 'utf8') | ||
@@ -142,6 +134,6 @@ Creates a readable stream for an existing object in the storage. Throws an error | ||
* `ext` is a default extension added to file name for the object (optional, | ||
default: `this.ext`) | ||
* `part` is a extension added to file name which can be later commited | ||
(optional, default: `this.part`) | ||
- `ext` is a default extension added to file name for the object (optional, | ||
default: `this.ext`) | ||
- `part` is a extension added to file name which can be later commited | ||
(optional, default: `this.part`) | ||
@@ -160,4 +152,4 @@ Commits the object in the storage. It means that file name for the object is | ||
* `ext` is a default extension added to file name for the object (optional, | ||
default: `this.ext`) | ||
- `ext` is a default extension added to file name for the object (optional, | ||
default: `this.ext`) | ||
@@ -164,0 +156,0 @@ Removes the object from the storage. Throws an error if has occurred or the |
/// <reference types="node" /> | ||
import fs from 'fs' | ||
import mkdir from 'fs.mkdir-shim' | ||
import path from 'path' | ||
import util from 'util' | ||
import fs from "fs" | ||
import mkdir from "fs.mkdir-shim" | ||
import path from "path" | ||
import util from "util" | ||
@@ -46,4 +46,4 @@ export interface FsBlobStorageOptions { | ||
export class FsBlobStorage { | ||
static readonly DEFAULT_EXT = '' | ||
static readonly DEFAULT_PART = '.part' | ||
static readonly DEFAULT_EXT = "" | ||
static readonly DEFAULT_PART = ".part" | ||
@@ -61,9 +61,9 @@ protected ext: string | ||
this.part = options.part !== undefined ? options.part : FsBlobStorage.DEFAULT_PART | ||
this.writeFlags = options.exclusive ? 'wx' : 'w' | ||
this.writeFlags = options.exclusive ? "wx" : "w" | ||
this.fs = options.fs || fs | ||
this.path = options.path || '.' | ||
this.path = options.path || "." | ||
this.fsPromises = {} as FsPromises | ||
this.fsPromises.mkdir = util.promisify(mkdir) | ||
for (const method of ['close', 'open', 'rename', 'stat', 'unlink'] as Array<keyof FsPromises>) { | ||
for (const method of ["close", "open", "rename", "stat", "unlink"] as Array<keyof FsPromises>) { | ||
this.fsPromises[method] = util.promisify(this.fs[method]) as any | ||
@@ -102,3 +102,3 @@ } | ||
const fd = await this.fsPromises.open(filepath, 'r') | ||
const fd = await this.fsPromises.open(filepath, "r") | ||
@@ -109,3 +109,3 @@ const stats = await this.fsPromises.stat(filepath) | ||
throw Object.assign(new Error(`ENOENT: empty file, open '${filepath}'`), { | ||
code: 'ENOENT', | ||
code: "ENOENT", | ||
path: filepath, | ||
@@ -112,0 +112,0 @@ }) |
@@ -13,4 +13,5 @@ { | ||
"outDir": "./lib", | ||
"sourceMap": true, | ||
"strict": true, | ||
"target": "es2017", | ||
"strict": true, | ||
"typeRoots": ["node_modules/@types"] | ||
@@ -17,0 +18,0 @@ }, |
21681
10
240
160