mp3tag
Version:
A library for reading/writing mp3 tag data
39 lines (38 loc) • 1.38 kB
JavaScript
;
/** This module defines the DataSource class, which represents
* data, which hasn't been yet loaded into a buffer.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataSource = void 0;
const data_1 = require("./data");
const file_1 = require("./file");
class DataSource {
source;
offset;
size;
/** Constructs the data source from a file and optional offset and length.
*
* @param sourceFile a File where the data should be read from
* @param offset the offset, where the data starts (default: 0)
* @param size the length of the data block (default: sourceFile.size-offset)
*/
constructor(sourceFile, offset, size) {
if (!(sourceFile instanceof file_1.File)) {
throw new Error("source must be a File");
}
this.source = sourceFile;
this.offset = offset ?? 0;
this.size = size ?? (this.source.size - this.offset);
}
/** Converts the DataSource into a Data object. This works asynchronously, as it
* has to read the content from the file
*/
async toData() {
const buffer = await this.source.readSlice(this.offset, this.size);
return new data_1.Data(buffer);
}
toString() {
return "DataSource:[offset:" + this.offset + ",size:" + this.size + "]@File";
}
}
exports.DataSource = DataSource;