File tree 5 files changed +30
-2
lines changed
5 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -206,6 +206,11 @@ declare module '@isomorphic-git/lightning-fs' {
206
206
* @returns The size of a file or directory in bytes.
207
207
*/
208
208
du ( filepath : string ) : Promise < number >
209
+ /**
210
+ * Function that saves anything that need to be saved in IndexedBD or custom IDB object. Right now it saves SuperBlock so it's save to dump the object as dump it into a file (e.g. from a Browser)
211
+ * @returns Promise that resolves when super block is saved to file
212
+ */
213
+ flush ( ) : Promise < void >
209
214
}
210
215
211
216
export interface Options {
@@ -245,8 +250,19 @@ declare module '@isomorphic-git/lightning-fs' {
245
250
* @default false
246
251
*/
247
252
defer ?: boolean
248
-
253
+ db : FS . IDB
254
+ }
255
+ export interface IDB {
256
+ constructor ( dbname : string , storename : string ) : IDB
257
+ saveSuperblock ( sb : Uint8Array ) : TypeOrPromise < void >
258
+ loadSuperblock ( ) : TypeOrPromise < FS . SuperBlock >
259
+ loadFile ( inode : number ) : TypeOrPromise < Uint8Array >
260
+ writeFile ( inode : number , data : Uint8Array ) : TypeOrPromise < void >
261
+ wipe ( ) : TypeOrPromise < void >
262
+ close ( ) : TypeOrPromise < void >
249
263
}
264
+ type TypeOrPromise < T > = T | Promise < T >
265
+ export type SuperBlock = Map < string | number , any >
250
266
export interface MKDirOptions {
251
267
/**
252
268
* Posix mode permissions
Original file line number Diff line number Diff line change 47
47
},
48
48
"files" : [
49
49
" **/*.js" ,
50
+ " index.d.ts" ,
50
51
" !__tests__" ,
51
52
" !coverage"
52
53
],
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ const path = require("./path.js");
13
13
module . exports = class DefaultBackend {
14
14
constructor ( ) {
15
15
this . saveSuperblock = debounce ( ( ) => {
16
- this . _saveSuperblock ( ) ;
16
+ this . flush ( ) ;
17
17
} , 500 ) ;
18
18
}
19
19
async init ( name , {
@@ -180,4 +180,7 @@ module.exports = class DefaultBackend {
180
180
du ( filepath ) {
181
181
return this . _cache . du ( filepath ) ;
182
182
}
183
+ flush ( ) {
184
+ return this . _saveSuperblock ( ) ;
185
+ }
183
186
}
Original file line number Diff line number Diff line change @@ -198,4 +198,7 @@ module.exports = class PromisifiedFS {
198
198
async du ( filepath ) {
199
199
return this . _backend . du ( filepath ) ;
200
200
}
201
+ async flush ( ) {
202
+ return this . _backend . flush ( ) ;
203
+ }
201
204
}
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ module.exports = class FS {
29
29
this . symlink = this . symlink . bind ( this )
30
30
this . backFile = this . backFile . bind ( this )
31
31
this . du = this . du . bind ( this )
32
+ this . flush = this . flush . bind ( this )
32
33
}
33
34
init ( name , options ) {
34
35
return this . promises . init ( name , options )
@@ -85,4 +86,8 @@ module.exports = class FS {
85
86
const [ resolve , reject ] = wrapCallback ( cb ) ;
86
87
this . promises . du ( filepath ) . then ( resolve ) . catch ( reject ) ;
87
88
}
89
+ flush ( cb ) {
90
+ const [ resolve , reject ] = wrapCallback ( cb ) ;
91
+ this . promises . flush ( ) . then ( resolve ) . catch ( reject ) ;
92
+ }
88
93
}
You can’t perform that action at this time.
0 commit comments