Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
debug('WAVE/non-PCM format=' + fmt.wFormatTag);
subFormat = 'non-PCM (' + fmt.wFormatTag + ')';
}
this.metadata.setFormat('codec', subFormat);
this.metadata.setFormat('bitsPerSample', fmt.wBitsPerSample);
this.metadata.setFormat('sampleRate', fmt.nSamplesPerSec);
this.metadata.setFormat('numberOfChannels', fmt.nChannels);
this.metadata.setFormat('bitrate', fmt.nBlockAlign * fmt.nSamplesPerSec * 8);
this.blockAlign = fmt.nBlockAlign;
break;
case 'id3 ': // The way Picard, FooBar currently stores, ID3 meta-data
case 'ID3 ': // The way Mp3Tags stores ID3 meta-data
const id3_data = await this.tokenizer.readToken(new Token.BufferType(header.chunkSize));
const id3stream = new ID3Stream(id3_data);
const rst = strtok3.fromStream(id3stream);
await new ID3v2Parser().parse(this.metadata, rst, this.options);
break;
case 'data': // PCM-data
if (this.metadata.format.lossless !== false) {
this.metadata.setFormat('lossless', true);
}
const numberOfSamples = this.fact ? this.fact.dwSampleLength : (header.chunkSize / this.blockAlign);
this.metadata.setFormat('numberOfSamples', numberOfSamples);
this.metadata.setFormat('duration', numberOfSamples / this.metadata.format.sampleRate);
this.metadata.setFormat('bitrate', this.metadata.format.numberOfChannels * this.blockAlign * this.metadata.format.sampleRate); // ToDo: check me
await this.tokenizer.ignore(header.chunkSize);
break;
default:
switch (header.chunkID) {
case 'COMM': // The Common Chunk
const common = await this.tokenizer.readToken(new AiffToken.Common(header, this.isCompressed));
this.metadata.setFormat('bitsPerSample', common.sampleSize);
this.metadata.setFormat('sampleRate', common.sampleRate);
this.metadata.setFormat('numberOfChannels', common.numChannels);
this.metadata.setFormat('numberOfSamples', common.numSampleFrames);
this.metadata.setFormat('duration', common.numSampleFrames / common.sampleRate);
this.metadata.setFormat('codec', common.compressionName);
return header.chunkSize;
case 'ID3 ': // ID3-meta-data
const id3_data = await this.tokenizer.readToken(new Token.BufferType(header.chunkSize));
const id3stream = new ID3Stream(id3_data);
const rst = strtok3.fromStream(id3stream);
await new ID3v2Parser().parse(this.metadata, rst, this.options);
return header.chunkSize;
case 'SSND': // Sound Data Chunk
if (this.metadata.format.duration) {
this.metadata.setFormat('bitrate', 8 * header.chunkSize / this.metadata.format.duration);
}
return 0;
default:
return 0;
}
}
case 'FVER': // 3.1 FORMAT VERSION CHUNK
const version = await this.tokenizer.readToken(Token.UINT32_LE);
debug(`DSDIFF version=${version}`);
break;
case 'PROP': // 3.2 PROPERTY CHUNK
const propType = await this.tokenizer.readToken(FourCcToken);
assert.strictEqual(propType, 'SND ');
await this.handleSoundPropertyChunks(header.chunkSize - FourCcToken.len);
break;
case 'ID3': // Unofficial ID3 tag support
const id3_data = await this.tokenizer.readToken(new Token.BufferType(header.chunkSize));
const id3stream = new ID3Stream(id3_data);
const rst = strtok3.fromStream(id3stream);
await new ID3v2Parser().parse(this.metadata, rst, this.options);
break;
default:
debug(`Ignore chunk[ID=${header.chunkID}, size=${header.chunkSize}]`);
break;
case 'DSD':
this.metadata.setFormat('numberOfSamples', header.chunkSize * 8 / this.metadata.format.numberOfChannels);
this.metadata.setFormat('duration', this.metadata.format.numberOfSamples / this.metadata.format.sampleRate);
break;
}
const remaining = header.chunkSize - (this.tokenizer.position - p0);
if (remaining > 0) {
debug(`After Parsing chunk, remaining ${remaining} bytes`);
async function fromStream(stream) {
const tokenizer = await strtok3.fromStream(stream);
try {
return await fromTokenizer(tokenizer);
} finally {
await tokenizer.close();
}
}
export function parseStream(stream: Stream.Readable, mimeType?: string, options: IOptions = {}): Promise {
return parseFromTokenizer(strtok3.fromStream(stream), mimeType, options);
}