chunkLength: number
- private pendingPut: { id: number, buf: Buffer, cb: Function }[] = []
+ private pendingPut: { id: number, buf: Buffer, cb: (err?: Error) => void }[] = []
// If the store is full
private memoryChunks: { [ id: number ]: Buffer | true } = {}
private databaseName: string
this.databaseName = 'webtorrent-chunks-'
if (!opts) opts = {}
- if (opts.torrent && opts.torrent.infoHash) this.databaseName += opts.torrent.infoHash
+ if (opts.torrent?.infoHash) this.databaseName += opts.torrent.infoHash
else this.databaseName += '-default'
this.setMaxListeners(100)
} catch (err) {
console.log('Cannot bulk insert chunks. Store them in memory.', { err })
- processing.forEach(p => this.memoryChunks[ p.id ] = p.buf)
+ processing.forEach(p => {
+ this.memoryChunks[p.id] = p.buf
+ })
} finally {
processing.forEach(p => p.cb())
}
// Chunk in store
this.db.transaction('r', this.db.chunks, async () => {
const result = await this.db.chunks.get({ id: index })
- if (result === undefined) return cb(null, new Buffer(0))
+ if (result === undefined) return cb(null, Buffer.alloc(0))
const buf = result.buf
if (!opts) return this.nextTick(cb, null, buf)
}
if (this.db) {
- await this.db.close()
+ this.db.close()
await this.dropDatabase(this.databaseName)
}
if (this.expirationDB) {
- await this.expirationDB.close()
+ this.expirationDB.close()
this.expirationDB = null
}
private runCleaner () {
this.checkExpiration()
- this.cleanerInterval = setInterval(async () => {
+ this.cleanerInterval = setInterval(() => {
this.checkExpiration()
}, PeertubeChunkStore.CLEANER_INTERVAL_MS)
}