How to use the strtok3/lib/core.fromStream function in strtok3

To help you get started, we’ve selected a few strtok3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Borewit / music-metadata / lib / riff / WaveParser.ts View on Github external
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:
github Borewit / music-metadata / lib / aiff / AiffParser.ts View on Github external
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;
    }
  }
github Borewit / music-metadata / lib / dsdiff / DsdiffParser.ts View on Github external
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`);
github sindresorhus / file-type / core.js View on Github external
async function fromStream(stream) {
	const tokenizer = await strtok3.fromStream(stream);
	try {
		return await fromTokenizer(tokenizer);
	} finally {
		await tokenizer.close();
	}
}
github Borewit / music-metadata / lib / core.ts View on Github external
export function parseStream(stream: Stream.Readable, mimeType?: string, options: IOptions = {}): Promise {
  return parseFromTokenizer(strtok3.fromStream(stream), mimeType, options);
}

strtok3

A promise based streaming tokenizer

MIT
Latest version published 21 days ago

Package Health Score

80 / 100
Full package analysis