Skip to content

Commit f2dfe43

Browse files
committed
defaultExt and defaultPart options has need renamed to ext and part
1 parent cae00e9 commit f2dfe43

File tree

6 files changed

+32
-27
lines changed

6 files changed

+32
-27
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## v1.1.0 2018-09-07
4+
5+
* The `defaultExt` and `defaultPart` options has need renamed to `ext` and
6+
`part`.
7+
38
## v1.0.0 2018-09-07
49

510
* Rewritten in Typescript.

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ const storage = new FsBlobStorage(options)
6363

6464
_Options:_
6565

66-
* `defaultExt` is a default `ext` argument for methods (optional, default: `''`)
67-
* `defaultPart` is a default `part` argument for methods (optional, default:
66+
* `ext` is a default `ext` argument for methods (optional, default: `''`)
67+
* `part` is a default `part` argument for methods (optional, default:
6868
`'.part'`)
6969
* `exclusive` if is true then can't create new object if already exists with
7070
the same key (optional, default: `false`)
@@ -76,7 +76,7 @@ _Example:_
7676

7777
```js
7878
const storage = new FsBlobStorage({
79-
defaultPart: '.lock',
79+
part: '.lock',
8080
path: '/var/spool/mail',
8181
exclusive: true
8282
})
@@ -91,9 +91,9 @@ const writable = await storage.createWriteStream(key, options)
9191
_Options:_
9292

9393
* `ext` is a default extension added to file name for the object (optional,
94-
default: `this.defaultExt`)
94+
default: `this.ext`)
9595
* `part` is a extension added to file name which can be later commited
96-
(optional, default: `this.defaultPart`)
96+
(optional, default: `this.part`)
9797
* `encoding` is a encoding for created file (optional, default: `null`)
9898

9999
Creates a writable stream for a new object in the storage. Object is stored with
@@ -124,9 +124,9 @@ await storage.commit(key, options)
124124
_Options:_
125125

126126
* `ext` is a default extension added to file name for the object (optional,
127-
default: `this.defaultExt`)
127+
default: `this.ext`)
128128
* `part` is a extension added to file name which can be later commited
129-
(optional, default: `this.defaultPart`)
129+
(optional, default: `this.part`)
130130

131131
Commits the object in the storage. It means that file name for the object is
132132
renamed and the additional extension for partial objects is removed. Throws an
@@ -141,7 +141,7 @@ await storage.remove(key, options)
141141
_Options:_
142142

143143
* `ext` is a default extension added to file name for the object (optional,
144-
default: `this.defaultExt`)
144+
default: `this.ext`)
145145

146146
Removes the object from the storage. Throws an error if has occurred or the
147147
object doesn't exist.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fs-blob-storage",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Blob storage on filesystem, with streams and promises API",
55
"main": "lib/fs-blob-storage.js",
66
"typings": "lib/fs-blob-storage.d.ts",

src/fs-blob-storage.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import util from 'util'
99
const promisify = require('util.promisify') as typeof util.promisify
1010

1111
export interface FsBlobStorageOptions {
12-
defaultExt?: string
13-
defaultPart?: string
12+
ext?: string
13+
part?: string
1414
exclusive?: boolean
1515
path?: string
1616
fs?: typeof fs
@@ -48,17 +48,17 @@ const DEFAULT_EXT = ''
4848
const DEFAULT_PART = '.part'
4949

5050
export class FsBlobStorage {
51-
protected defaultExt: string
52-
protected defaultPart: string
51+
protected ext: string
52+
protected part: string
5353
protected writeFlags: string
5454
protected fs: typeof fs
5555
protected path: string
5656

5757
protected fsPromises: FsPromises
5858

5959
constructor (options: FsBlobStorageOptions = {}) {
60-
this.defaultExt = options.defaultExt !== undefined ? options.defaultExt : DEFAULT_EXT
61-
this.defaultPart = options.defaultPart !== undefined ? options.defaultPart : DEFAULT_PART
60+
this.ext = options.ext !== undefined ? options.ext : DEFAULT_EXT
61+
this.part = options.part !== undefined ? options.part : DEFAULT_PART
6262
this.writeFlags = options.exclusive ? 'wx' : 'w'
6363
this.fs = options.fs || fs
6464
this.path = options.path || '.'
@@ -70,7 +70,7 @@ export class FsBlobStorage {
7070
}
7171

7272
async createWriteStream (key: string, options: FsBlobStorageWriteStreamOptions = {}): Promise<fs.WriteStream> {
73-
const { ext = this.defaultExt, part = this.defaultPart, encoding } = options
73+
const { ext = this.ext, part = this.part, encoding } = options
7474
const filepath = path.join(this.path, key + ext)
7575
const dirpath = path.dirname(filepath)
7676

@@ -95,7 +95,7 @@ export class FsBlobStorage {
9595
}
9696

9797
async createReadStream (key: string, options: FsBlobStorageReadStreamOptions = {}): Promise<fs.ReadStream> {
98-
const { ext = this.defaultExt, encoding } = options
98+
const { ext = this.ext, encoding } = options
9999
const filepath = path.join(this.path, key + ext)
100100

101101
const fd = await this.fsPromises.open(filepath, 'r')
@@ -110,15 +110,15 @@ export class FsBlobStorage {
110110
}
111111

112112
async commit (key: string, options: FsBlobStorageCommitOptions = {}): Promise<void> {
113-
const { ext = this.defaultExt, part = this.defaultPart } = options
113+
const { ext = this.ext, part = this.part } = options
114114
if (part) {
115115
const filepath = path.join(this.path, key + ext)
116116
return this.fsPromises.rename(filepath + part, filepath)
117117
}
118118
}
119119

120120
async remove (key: string, options: FsBlobStorageRemoveOptions = {}): Promise<void> {
121-
const { ext = this.defaultExt } = options
121+
const { ext = this.ext } = options
122122
const filepath = path.join(this.path, key + ext)
123123
return this.fsPromises.unlink(filepath)
124124
}

test/fs-blob-storage-with-default-ext.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import mockFs from './lib/mock-fs'
1212

1313
const STORAGEDIR = '/tmp/storage'
1414

15-
Feature('Test FsBlobStorage with defaultExt option', () => {
15+
Feature('Test FsBlobStorage with ext option', () => {
1616
const fakeFilesystem = {
1717
[STORAGEDIR]: {
1818
'commit.txt.part': 'another file content here',
@@ -33,7 +33,7 @@ Feature('Test FsBlobStorage with defaultExt option', () => {
3333
})
3434

3535
Given('FsBlobStorage object', () => {
36-
storage = new FsBlobStorage({ path: STORAGEDIR, defaultExt: '.txt', fs: mockFs })
36+
storage = new FsBlobStorage({ path: STORAGEDIR, ext: '.txt', fs: mockFs })
3737
})
3838

3939
When('key test is passed in', async () => {
@@ -70,7 +70,7 @@ Feature('Test FsBlobStorage with defaultExt option', () => {
7070
})
7171

7272
Given('FsBlobStorage object', () => {
73-
storage = new FsBlobStorage({ path: STORAGEDIR, defaultExt: '.txt', fs: mockFs })
73+
storage = new FsBlobStorage({ path: STORAGEDIR, ext: '.txt', fs: mockFs })
7474
})
7575

7676
When('key test is passed in', async () => {
@@ -98,7 +98,7 @@ Feature('Test FsBlobStorage with defaultExt option', () => {
9898
})
9999

100100
Given('FsBlobStorage object', () => {
101-
storage = new FsBlobStorage({ path: STORAGEDIR, defaultExt: '.txt', fs: mockFs })
101+
storage = new FsBlobStorage({ path: STORAGEDIR, ext: '.txt', fs: mockFs })
102102
})
103103

104104
When('key rs is passed in', async () => {
@@ -121,7 +121,7 @@ Feature('Test FsBlobStorage with defaultExt option', () => {
121121
})
122122

123123
Given('FsBlobStorage object', () => {
124-
storage = new FsBlobStorage({ path: STORAGEDIR, defaultExt: '.txt', fs: mockFs })
124+
storage = new FsBlobStorage({ path: STORAGEDIR, ext: '.txt', fs: mockFs })
125125
})
126126

127127
When('key remove is passed in', async () => {

test/fs-blob-storage-with-default-part.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import mockFs from './lib/mock-fs'
1212

1313
const STORAGEDIR = '/tmp/storage'
1414

15-
Feature('Test FsBlobStorage with defaultPart option', () => {
15+
Feature('Test FsBlobStorage with part option', () => {
1616
const fakeFilesystem = {
1717
[STORAGEDIR]: {
1818
'commit.txt.lock': 'another file content here',
@@ -33,7 +33,7 @@ Feature('Test FsBlobStorage with defaultPart option', () => {
3333
})
3434

3535
Given('FsBlobStorage object', () => {
36-
storage = new FsBlobStorage({ path: STORAGEDIR, defaultPart: '.lock', fs: mockFs })
36+
storage = new FsBlobStorage({ path: STORAGEDIR, part: '.lock', fs: mockFs })
3737
})
3838

3939
When('key test is passed in', async () => {
@@ -98,7 +98,7 @@ Feature('Test FsBlobStorage with defaultPart option', () => {
9898
})
9999

100100
Given('FsBlobStorage object', () => {
101-
storage = new FsBlobStorage({ path: STORAGEDIR, defaultPart: '.lock', fs: mockFs })
101+
storage = new FsBlobStorage({ path: STORAGEDIR, part: '.lock', fs: mockFs })
102102
})
103103

104104
When('key rs is passed in', async () => {

0 commit comments

Comments
 (0)