@@ -115,11 +115,12 @@ class RandomAccessIdb extends EventEmitter {
115
115
this . queue . addTask ( async ( ) => {
116
116
await this . ensureDBReady ( ) ;
117
117
118
- // If metadata doesn't exist, initialize it with default values
119
- if ( ! this . meta || isNaN ( this . meta . length ) ) {
118
+ // If metadata doesn't exist, initialize it
119
+ if ( ! this . meta ) {
120
120
this . meta = { fileName : this . fileName , chunkSize : this . chunkSize , length : 0 } ;
121
121
}
122
122
123
+ // Proceed with writing logic...
123
124
const blocks = this . _blocks ( offset , offset + data . length ) ;
124
125
const db = this . db ;
125
126
const tx = db . transaction ( 'chunks' , 'readwrite' ) ;
@@ -137,14 +138,15 @@ class RandomAccessIdb extends EventEmitter {
137
138
await tx . done ;
138
139
139
140
const newLength = Math . max ( this . meta . length , offset + data . length ) ;
140
- this . meta . length = isNaN ( newLength ) ? 0 : newLength ; // Sanitize length value
141
+ this . meta . length = newLength ;
141
142
await this . metaManager . set ( this . meta ) ; // Persist metadata
142
143
143
- cb ( null ) ; // Signal success
144
+ cb ( null ) ; // Success
144
145
} ) . catch ( cb ) ;
145
146
}
146
147
147
148
149
+
148
150
read ( offset , size , cb = ( ) => { } ) {
149
151
this . queue . addTask ( async ( ) => {
150
152
await this . ensureDBReady ( ) ;
@@ -379,17 +381,17 @@ class RandomAccessIdb extends EventEmitter {
379
381
try {
380
382
const dbExists = await this . _verifyDatabaseExists ( ) ;
381
383
if ( dbExists ) {
382
- console . log ( `Purging file ${ this . fileName } from database` ) ;
384
+ // console.log(`Purging file ${this.fileName} from database`);
383
385
384
386
// Attempt to delete the database
385
387
await IDB . deleteDB ( this . fileName ) ;
386
388
const isDeleted = ! ( await this . _verifyDatabaseExists ( ) ) ;
387
389
388
390
if ( ! isDeleted ) {
389
- console . warn ( `Database ${ this . fileName } may not have been deleted.` ) ;
391
+ // console.warn(`Database ${this.fileName} may not have been deleted.`);
390
392
}
391
393
} else {
392
- console . warn ( `Database ${ this . fileName } does not exist, skipping database deletion.` ) ;
394
+ // console.warn(`Database ${this.fileName} does not exist, skipping database deletion.`);
393
395
}
394
396
395
397
// Purge the metadata (always attempt this)
@@ -399,7 +401,7 @@ class RandomAccessIdb extends EventEmitter {
399
401
400
402
// Remove from loaded files
401
403
allLoadedFiles . delete ( this . fileName ) ;
402
- console . log ( `Purge complete for file ${ this . fileName } ` ) ;
404
+ // console.log(`Purge complete for file ${this.fileName}`);
403
405
404
406
cb ( null ) ; // Success callback
405
407
} catch ( e ) {
0 commit comments