File tree 3 files changed +16
-3
lines changed
3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -135,10 +135,12 @@ Returns the entry at `path` in the drive. It looks like this:
135
135
136
136
Deletes the file at ` path ` from the drive.
137
137
138
- #### ` await drive.clear(path) `
138
+ #### ` await drive.clear(path, [options] ) `
139
139
140
140
Deletes the blob from storage to free up space, but the file structure reference is kept.
141
141
142
+ If ` storageInfo = true ` is set, an estimate of the amount of bytes freed will be returned (default ` false ` ).
143
+
142
144
#### ` await drive.symlink(path, linkname) `
143
145
144
146
Creates an entry in drive at ` path ` that points to the entry at ` linkname ` .
Original file line number Diff line number Diff line change @@ -190,12 +190,22 @@ module.exports = class Hyperdrive extends ReadyResource {
190
190
return this . files . del ( normalizePath ( name ) )
191
191
}
192
192
193
- async clear ( name ) {
193
+ async clear ( name , { storageInfo = false } = { } ) {
194
194
const node = await this . entry ( name )
195
195
if ( node === null ) return
196
196
197
+ const infoBefore = storageInfo
198
+ ? await this . blobs . core . info ( { storage : true } )
199
+ : null
200
+
197
201
await this . getBlobs ( )
198
202
await this . blobs . clear ( node . value . blob )
203
+
204
+ if ( infoBefore ) {
205
+ const infoAfter = await this . blobs . core . info ( { storage : true } )
206
+ const bytesCleared = infoBefore . storage . blocks - infoAfter . storage . blocks
207
+ return bytesCleared
208
+ }
199
209
}
200
210
201
211
async symlink ( name , dst , { metadata = null } = { } ) {
Original file line number Diff line number Diff line change @@ -749,7 +749,8 @@ test('drive.clear(path)', async (t) => {
749
749
const initContent = await drive . blobs . get ( entry . value . blob , { wait : false } )
750
750
t . alike ( initContent , b4a . from ( 'hello world' ) )
751
751
752
- await drive . clear ( '/loc' )
752
+ const res = await drive . clear ( '/loc' )
753
+ t . is ( res , undefined )
753
754
754
755
// Entry still exists (so file not deleted)
755
756
const nowEntry = await drive . entry ( '/loc' )
You can’t perform that action at this time.
0 commit comments