🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

fs-blob-storage

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs-blob-storage - npm Package Compare versions

Comparing version

to
0.6.0

.markdownlint.json
# Changelog
## v0.6.0 2018-07-16
* New option `fs` with File System module.
* Tests don't use `mock-fs` package anymore.
* Tweaked jsdoc.
## v0.5.2 2018-05-24

@@ -4,0 +10,0 @@

4

lib/fs-blob-storage.d.ts

@@ -10,2 +10,3 @@ /// <reference types="node" />

path?: string
fs?: typeof fs
}

@@ -34,5 +35,2 @@

export class FsBlobStorage {
private readonly path: string
private readonly writeFlags: string
constructor (options?: FsBlobStorageOptions)

@@ -39,0 +37,0 @@

@@ -6,8 +6,2 @@ const fs = require('fs')

const fsPromises = {}
for (const method of ['close', 'open', 'rename', 'stat', 'unlink']) {
fsPromises[method] = promisify(fs[method])
}
const DEFAULT_EXT = ''

@@ -17,36 +11,9 @@ const DEFAULT_PART = '.part'

/**
* @interface FsBlobStorageOptions
* @property {string} [defaultExt]
* @property {string} [defaultPart]
* @property {boolean} [exclusive]
* @property {string} [path]
*/
/**
* @interface FsBlobStorageWriteStreamOptions
* @property {string} [ext]
* @property {string} [part]
* @property {string} [encoding]
*/
/**
* @interface FsBlobStorageReadStreamOptions
* @property {string} [ext]
* @property {string} [encoding]
*/
/**
* @interface FsBlobStorageCommitOptions
* @property {string} [ext]
* @property {string} [part]
*/
/**
* @interface FsBlobStorageRemoveOptions
* @property {string} [ext]
*/
/**
* @class
* @param {FsBlobStorageOptions} [options]
* @param {Object} [options]
* @param {string} [options.defaultExt]
* @param {string} [options.defaultPart]
* @param {boolean} [options.exclusive]
* @param {Object} [options.fs]
* @param {string} [options.path]
*/

@@ -58,8 +25,18 @@ class FsBlobStorage {

this.writeFlags = options.exclusive ? 'wx' : 'w'
this.fs = options.fs || fs
this.path = options.path || '.'
this.fsPromises = {}
for (const method of ['close', 'open', 'rename', 'stat', 'unlink']) {
this.fsPromises[method] = promisify(this.fs[method])
}
}
/**
* @async
* @param {string} key
* @param {FsBlobStorageWriteStreamOptions} [options]
* @param {Object} [options]
* @param {string} [options.ext]
* @param {string} [options.part]
* @param {string} [options.encoding]
* @returns {Promise<Writable>}

@@ -75,25 +52,25 @@ */

return makeDir(dirpath).then(() => {
return makeDir(dirpath, { fs: this.fs }).then(() => {
// for exclusive mode it will reject if file already exist
return fsPromises.open(filepath, this.writeFlags)
return this.fsPromises.open(filepath, this.writeFlags)
}).then((value) => {
fd = value
// do `open` instead of `stat` to prevent race condition
return fsPromises.open(filepath + part, this.writeFlags)
return this.fsPromises.open(filepath + part, this.writeFlags)
}).then((fdPart) => {
// `close` before `rename` just for Windows
return fsPromises.close(fdPart)
return this.fsPromises.close(fdPart)
}).then(() => {
// `rename` overwrites quietly the file
return fsPromises.rename(filepath, filepath + part)
return this.fsPromises.rename(filepath, filepath + part)
}).then(() => {
// first argument is ignored
return fs.createWriteStream(filepath + part, { fd, encoding })
return this.fs.createWriteStream(filepath + part, { fd, encoding })
})
}
return makeDir(dirpath).then(() => {
return fsPromises.open(filepath, this.writeFlags)
return makeDir(dirpath, { fs: this.fs }).then(() => {
return this.fsPromises.open(filepath, this.writeFlags)
}).then((fd) => {
return fs.createWriteStream(filepath, { fd, encoding })
return this.fs.createWriteStream(filepath, { fd, encoding })
})

@@ -103,4 +80,7 @@ }

/**
* @async
* @param {string} key
* @param {FsBlobStorageReadStreamOptions} [options]
* @param {Object} [options]
* @param {string} [options.ext]
* @param {string} [options.encoding]
* @returns {Promise<Readable>}

@@ -114,5 +94,5 @@ */

return fsPromises.open(filepath, 'r').then((value) => {
return this.fsPromises.open(filepath, 'r').then((value) => {
fd = value
return fsPromises.stat(filepath)
return this.fsPromises.stat(filepath)
}).then((stats) => {

@@ -123,3 +103,3 @@ if (!stats.size) {

return fs.createReadStream(filepath, { fd, encoding })
return this.fs.createReadStream(filepath, { fd, encoding })
})

@@ -129,5 +109,8 @@ }

/**
* @async
* @param {string} key
* @param {FsBlobStorageCommitOptions} [options]
* @returns {Promise<void>}
* @param {Object} [options]
* @param {string} [options.ext]
* @param {string} [options.part]
* @returns {Promise<undefined>}
*/

@@ -138,3 +121,3 @@ commit (key, options = {}) {

const filepath = path.join(this.path, key + ext)
return fsPromises.rename(filepath + part, filepath)
return this.fsPromises.rename(filepath + part, filepath)
}

@@ -144,5 +127,7 @@ }

/**
* @async
* @param {string} key
* @param {FsBlobStorageRemoveOptions} [options]
* @returns {Promise<void>}
* @param {Object} [options]
* @param {string} [options.ext]
* @returns {Promise<undefined>}
*/

@@ -152,3 +137,3 @@ remove (key, options = {}) {

const filepath = path.join(this.path, key + ext)
return fsPromises.unlink(filepath)
return this.fsPromises.unlink(filepath)
}

@@ -155,0 +140,0 @@ }

{
"name": "fs-blob-storage",
"version": "0.5.2",
"description": "Blob storage on filesystem with promises API",
"version": "0.6.0",
"description": "Blob storage on filesystem, with streams and promises API",
"main": "lib/fs-blob-storage.js",

@@ -32,22 +32,21 @@ "typings": "lib/fs-blob-storage.d.ts",

"@types/make-dir": "^1.0.3",
"@types/node": "^10.1.2",
"@types/node": "^10.5.2",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"eslint": "^4.19.1",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.12.0",
"eslint": "^5.1.0",
"eslint-config-standard": "^12.0.0-alpha.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.7.0",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0",
"markdownlint-cli": "^0.9.0",
"mock-fs": "^4.5.0",
"markdownlint-cli": "^0.11.0",
"promise-readable": "^3.1.5",
"promise-writable": "^3.1.2",
"standard": "^11.0.1",
"stream.pipeline-shim": "^1.0.2",
"stream.pipeline-shim": "^1.0.4",
"tap": "^12.0.1",
"tap-given": "^0.6.0",
"tslint": "^5.10.0",
"tslint-config-standard": "^7.0.0",
"typescript": "^2.8.3"
"tslint-config-standard": "^7.1.0",
"typescript": "^2.9.2"
},

@@ -54,0 +53,0 @@ "scripts": {

# 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 -->
Blob storage on filesystem with promises API.
Blob storage on filesystem, with streams and promises API.
Features:
* Simple API
* Read and write file streams
* Partial files
* Safe, atomic operations
* Works with any POSIX or NTFS filesystem
* NFS friendly locking
## Requirements

@@ -43,8 +54,10 @@

* `defaultExt` is a default `ext` argument for methods (optional, default: "")
* `defaultExt` is a default `ext` argument for methods (optional, default: `''`)
* `defaultPart` is a default `part` argument for methods (optional, default:
".part")
`'.part'`)
* `exclusive` if is true then can't create new object if already exists with
the same key (optional, default: false)
* `path` is a directory path of the storage (optional, default: ".")
the same key (optional, default: `false`)
* `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: `'.'`)

@@ -88,4 +101,4 @@ _Example:_

* `ext` is a default extension added to file name for the object (optional,
default: "")
* `encoding` is a encoding for created file (optional, default: "utf8")
default: '')
* `encoding` is a encoding for created file (optional, default: 'utf8')

@@ -126,2 +139,7 @@ Creates a readable stream for an existing object in the storage. Throws an error

## Bugs
This storage doesn't work correctly on NTFS filesystem mounted in Linux in
VirtualBox. In this case no partial files should be used.
## License

@@ -128,0 +146,0 @@

@@ -11,3 +11,3 @@ 'use strict'

const mockFs = require('mock-fs')
const mockFs = require('../mock/mock-fs')

@@ -32,7 +32,7 @@ const { FsBlobStorage } = require('../lib/fs-blob-storage')

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -51,6 +51,2 @@

})
After(() => {
mockFs.restore()
})
})

@@ -65,7 +61,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -84,6 +80,2 @@

})
After(() => {
mockFs.restore()
})
})

@@ -98,7 +90,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -117,6 +109,2 @@

})
After(() => {
mockFs.restore()
})
})

@@ -131,7 +119,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -150,7 +138,3 @@

})
After(() => {
mockFs.restore()
})
})
})

@@ -11,3 +11,3 @@ 'use strict'

const mockFs = require('mock-fs')
const mockFs = require('../mock/mock-fs')

@@ -33,7 +33,7 @@ const { FsBlobStorage } = require('../lib/fs-blob-storage')

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR, exclusive: true })
storage = new FsBlobStorage({ path: STORAGEDIR, exclusive: true, fs: mockFs })
})

@@ -52,6 +52,2 @@

})
After(() => {
mockFs.restore()
})
})

@@ -66,7 +62,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR, exclusive: true })
storage = new FsBlobStorage({ path: STORAGEDIR, exclusive: true, fs: mockFs })
})

@@ -85,7 +81,3 @@

})
After(() => {
mockFs.restore()
})
})
})

@@ -11,6 +11,4 @@ 'use strict'

const mockFs = require('mock-fs')
const mockFs = require('../mock/mock-fs')
const fs = require('fs')
const { FsBlobStorage } = require('../lib/fs-blob-storage')

@@ -42,7 +40,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -62,3 +60,3 @@

And('.part file should be created', () => {
return fs.existsSync(realFilename).should.be.true
return mockFs.existsSync(realFilename).should.be.true
})

@@ -72,9 +70,5 @@

Then('new file contains the new content', () => {
const content = fs.readFileSync(realFilename, { encoding: 'utf8' })
const content = mockFs.readFileSync(realFilename, { encoding: 'utf8' })
content.should.equal('new content here')
})
After(() => {
mockFs.restore()
})
})

@@ -90,7 +84,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -110,3 +104,3 @@

And('.part file should be created', () => {
return fs.existsSync(realFilename).should.be.true
return mockFs.existsSync(realFilename).should.be.true
})

@@ -120,9 +114,5 @@

Then('new file contains the new content', () => {
const content = fs.readFileSync(realFilename, { encoding: 'utf8' })
const content = mockFs.readFileSync(realFilename, { encoding: 'utf8' })
content.should.equal('new content here')
})
After(() => {
mockFs.restore()
})
})

@@ -137,7 +127,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -150,9 +140,5 @@

Then('rs.part should be renamed to rs', () => {
return fs.existsSync(realFilename).should.be.true
return mockFs.existsSync(realFilename).should.be.true
})
After(() => {
mockFs.restore()
})
})
})

@@ -11,6 +11,4 @@ 'use strict'

const mockFs = require('mock-fs')
const mockFs = require('../mock/mock-fs')
const fs = require('fs')
const { FsBlobStorage } = require('../lib/fs-blob-storage')

@@ -42,7 +40,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR, defaultExt: '.txt' })
storage = new FsBlobStorage({ path: STORAGEDIR, defaultExt: '.txt', fs: mockFs })
})

@@ -62,3 +60,3 @@

And('.part file should be created', () => {
return fs.existsSync(realFilename).should.be.true
return mockFs.existsSync(realFilename).should.be.true
})

@@ -72,9 +70,5 @@

Then('new file contains the new content', () => {
const content = fs.readFileSync(realFilename, { encoding: 'utf8' })
const content = mockFs.readFileSync(realFilename, { encoding: 'utf8' })
content.should.equal('new content here')
})
After(() => {
mockFs.restore()
})
})

@@ -89,7 +83,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR, defaultExt: '.txt' })
storage = new FsBlobStorage({ path: STORAGEDIR, defaultExt: '.txt', fs: mockFs })
})

@@ -112,6 +106,2 @@

})
After(() => {
mockFs.restore()
})
})

@@ -126,7 +116,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR, defaultExt: '.txt' })
storage = new FsBlobStorage({ path: STORAGEDIR, defaultExt: '.txt', fs: mockFs })
})

@@ -139,8 +129,4 @@

Then('rs.part should be renamed to rs', () => {
return fs.existsSync(realFilename).should.be.true
return mockFs.existsSync(realFilename).should.be.true
})
After(() => {
mockFs.restore()
})
})

@@ -155,7 +141,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR, defaultExt: '.txt' })
storage = new FsBlobStorage({ path: STORAGEDIR, defaultExt: '.txt', fs: mockFs })
})

@@ -168,9 +154,5 @@

Then('remove should be removed', () => {
return fs.existsSync(realFilename).should.be.false
return mockFs.existsSync(realFilename).should.be.false
})
After(() => {
mockFs.restore()
})
})
})

@@ -11,6 +11,4 @@ 'use strict'

const mockFs = require('mock-fs')
const mockFs = require('../mock/mock-fs')
const fs = require('fs')
const { FsBlobStorage } = require('../lib/fs-blob-storage')

@@ -42,7 +40,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR, defaultPart: '.lock' })
storage = new FsBlobStorage({ path: STORAGEDIR, defaultPart: '.lock', fs: mockFs })
})

@@ -62,3 +60,3 @@

And('.part file should be created', () => {
return fs.existsSync(realFilename).should.be.true
return mockFs.existsSync(realFilename).should.be.true
})

@@ -72,9 +70,5 @@

Then('new file contains the new content', () => {
const content = fs.readFileSync(realFilename, { encoding: 'utf8' })
const content = mockFs.readFileSync(realFilename, { encoding: 'utf8' })
content.should.equal('new content here')
})
After(() => {
mockFs.restore()
})
})

@@ -89,7 +83,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -112,6 +106,2 @@

})
After(() => {
mockFs.restore()
})
})

@@ -126,7 +116,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR, defaultPart: '.lock' })
storage = new FsBlobStorage({ path: STORAGEDIR, defaultPart: '.lock', fs: mockFs })
})

@@ -139,8 +129,4 @@

Then('rs.part should be renamed to rs', () => {
return fs.existsSync(realFilename).should.be.true
return mockFs.existsSync(realFilename).should.be.true
})
After(() => {
mockFs.restore()
})
})

@@ -155,7 +141,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -168,9 +154,5 @@

Then('remove should be removed', () => {
return fs.existsSync(realFilename).should.be.false
return mockFs.existsSync(realFilename).should.be.false
})
After(() => {
mockFs.restore()
})
})
})

@@ -11,6 +11,4 @@ 'use strict'

const mockFs = require('mock-fs')
const mockFs = require('../mock/mock-fs')
const fs = require('fs')
const { FsBlobStorage } = require('../lib/fs-blob-storage')

@@ -43,7 +41,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -63,3 +61,3 @@

And('.part file should no be created', () => {
return fs.existsSync(realFilenamePart).should.be.false
return mockFs.existsSync(realFilenamePart).should.be.false
})

@@ -73,9 +71,5 @@

Then('new file contains the new content', () => {
const content = fs.readFileSync(realFilename, { encoding: 'utf8' })
const content = mockFs.readFileSync(realFilename, { encoding: 'utf8' })
content.should.equal('new content here')
})
After(() => {
mockFs.restore()
})
})

@@ -90,7 +84,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -113,6 +107,2 @@

})
After(() => {
mockFs.restore()
})
})

@@ -127,7 +117,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -140,8 +130,4 @@

Then('rs should exists', () => {
return fs.existsSync(realFilename).should.be.true
return mockFs.existsSync(realFilename).should.be.true
})
After(() => {
mockFs.restore()
})
})

@@ -156,7 +142,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -169,9 +155,5 @@

Then('remove should be removed', () => {
return fs.existsSync(realFilename).should.be.false
return mockFs.existsSync(realFilename).should.be.false
})
After(() => {
mockFs.restore()
})
})
})

@@ -11,6 +11,4 @@ 'use strict'

const mockFs = require('mock-fs')
const mockFs = require('../mock/mock-fs')
const fs = require('fs')
const { FsBlobStorage } = require('../lib/fs-blob-storage')

@@ -42,7 +40,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -62,3 +60,3 @@

And('.part file should be created', () => {
return fs.existsSync(realFilename).should.be.true
return mockFs.existsSync(realFilename).should.be.true
})

@@ -72,9 +70,5 @@

Then('new file contains the new content', () => {
const content = fs.readFileSync(realFilename, { encoding: 'utf8' })
const content = mockFs.readFileSync(realFilename, { encoding: 'utf8' })
content.should.equal('new content here')
})
After(() => {
mockFs.restore()
})
})

@@ -89,7 +83,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -112,6 +106,2 @@

})
After(() => {
mockFs.restore()
})
})

@@ -126,7 +116,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -139,8 +129,4 @@

Then('rs.part should be renamed to rs', () => {
return fs.existsSync(realFilename).should.be.true
return mockFs.existsSync(realFilename).should.be.true
})
After(() => {
mockFs.restore()
})
})

@@ -155,7 +141,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -168,9 +154,5 @@

Then('remove should be removed', () => {
return fs.existsSync(realFilename).should.be.false
return mockFs.existsSync(realFilename).should.be.false
})
After(() => {
mockFs.restore()
})
})
})

@@ -11,6 +11,4 @@ 'use strict'

const mockFs = require('mock-fs')
const mockFs = require('../mock/mock-fs')
const fs = require('fs')
const { FsBlobStorage } = require('../lib/fs-blob-storage')

@@ -21,2 +19,3 @@

const PromiseWritable = require('promise-writable')
const { Readable, Writable } = require('stream')

@@ -54,7 +53,7 @@ const STORAGEDIR = '/tmp/storage'

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -70,7 +69,7 @@

Then('created Writable should not be null', () => {
writable.should.be.an.instanceof(fs.WriteStream)
writable.should.be.an.instanceof(Writable)
})
And('.part file should be created', () => {
return fs.existsSync(realFilename).should.be.true
return mockFs.existsSync(realFilename).should.be.true
})

@@ -84,9 +83,5 @@

Then('new file contains the new content', () => {
const content = fs.readFileSync(realFilename, { encoding: 'utf8' })
const content = mockFs.readFileSync(realFilename, { encoding: 'utf8' })
content.should.equal('new content here')
})
After(() => {
mockFs.restore()
})
})

@@ -101,7 +96,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -117,3 +112,3 @@

Then('created Readable should not be null', () => {
readable.should.be.an.instanceof(fs.ReadStream)
readable.should.be.an.instanceof(Readable)
})

@@ -125,6 +120,2 @@

})
After(() => {
mockFs.restore()
})
})

@@ -139,7 +130,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -152,8 +143,4 @@

Then('rs.part should be renamed to rs', () => {
return fs.existsSync(realFilename).should.be.true
return mockFs.existsSync(realFilename).should.be.true
})
After(() => {
mockFs.restore()
})
})

@@ -168,7 +155,7 @@

Before(() => {
mockFs(fakeFilesystem)
mockFs.init(fakeFilesystem)
})
Given('FsBlobStorage object', () => {
storage = new FsBlobStorage({ path: STORAGEDIR })
storage = new FsBlobStorage({ path: STORAGEDIR, fs: mockFs })
})

@@ -181,9 +168,5 @@

Then('remove should be removed', () => {
return fs.existsSync(realFilename).should.be.false
return mockFs.existsSync(realFilename).should.be.false
})
After(() => {
mockFs.restore()
})
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet