filecoin-pin
Version:
Bridge IPFS content to Filecoin Onchain Cloud using familiar tools
36 lines • 1.61 kB
JavaScript
/**
* Node.js CAR Blockstore that writes blocks to a file on disk.
*/
import { EventEmitter } from 'node:events';
import { CARBlockstoreBase } from './car-blockstore-base.js';
import { CARFileBackend } from './car-file-backend.js';
/**
* A blockstore that writes blocks directly to a CAR file as they arrive.
* This eliminates the need for redundant storage during IPFS pinning operations.
*/
export class CARWritingBlockstore extends CARBlockstoreBase {
fileBackend;
eventEmitter;
constructor(options) {
const backend = new CARFileBackend(options.outputPath, options.logger);
const eventEmitter = new EventEmitter();
super(options.rootCID, backend, eventEmitter);
this.fileBackend = backend;
this.eventEmitter = eventEmitter;
// Forward events from backend to our event emitter
this.fileBackend.on('initialized', (data) => this.eventEmitter.emit('initialized', data));
this.fileBackend.on('block:stored', (data) => this.eventEmitter.emit('block:stored', data));
this.fileBackend.on('finalized', (data) => this.eventEmitter.emit('finalized', data || this.stats));
this.fileBackend.on('cleanup', () => this.eventEmitter.emit('cleanup'));
this.fileBackend.on('error', (error) => this.eventEmitter.emit('error', error));
}
// Expose event emitter methods for consumers
on(event, listener) {
this.eventEmitter.on(event, listener);
return this;
}
emit(event, ...args) {
return this.eventEmitter.emit(event, ...args);
}
}
//# sourceMappingURL=car-blockstore.js.map