Skip to content

Node.js module for streaming subsections of FLAC files

License

Notifications You must be signed in to change notification settings

lammas/flac-substream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.
);

About

Node.js module for streaming subsections of FLAC files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published