flac-substream

0.1.7 • Public • Published

flac-substream

NodeJS module for streaming subsections of FLAC files. This module is intended to accompany the flac-seektable module.

Install

npm install flac-substream

Usage

The module returns a single function:

substream(
	writable,        // A stream.Writable object for the output
	seekdata,        // Metadata object from flac-seektable module
	start,           // Start position (index into seekpoints)
	end,             // End position (index into seekpoints)
	get_read_stream  // Function with signature: (start, end), must return stream.Readable
)

The get_read_stream function must return a stream.Readable object that provides data from the FLAC file from offset start to offset end.

// Demonstrates the usage to perform random access on a file.
// This is by no means a practical example (most usecases would involve storage of the FLAC metadata beforehand).

const fs = require('fs');
const seektable = require('flac-seektable');
const substream = require('flac-substream');

const FLAC_IN = 'input.flac';
const FLAC_OUT = 'output.flac';
const START_SECONDS = 10;
const END_SECONDS = 20;

var reader = fs.createReadStream(FLAC_IN);
reader.pipe(new seektable(function(data) {
	var output = fs.createWriteStream(FLAC_OUT, { flags: 'w' });
	substream(output, data, START_SECONDS, END_SECONDS, function(start, end) {
		var stream = fs.createReadStream(
			FLAC_IN,
			{
				start: start,
				end: end
			}
		);
		return stream;
	});
})).pipe(
	devnull() // Or this could go to somewhere useful.
);

Readme

Keywords

Package Sidebar

Install

npm i flac-substream

Weekly Downloads

1

Version

0.1.7

License

MIT

Unpacked Size

6.57 kB

Total Files

5

Last publish

Collaborators

  • lammas