@@ -9,8 +9,8 @@ import util from 'util'
99const promisify = require ( 'util.promisify' ) as typeof util . promisify
1010
1111export 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 = ''
4848const DEFAULT_PART = '.part'
4949
5050export 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 }
0 commit comments