npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

readable-file-writer

v0.10.0

Published

A file writer that can also multicast data to multiple readers (Streams v2)

Downloads

6

Readme

readable-file-writer

A file writer that can also multicast data to multiple readers (Streams v2)

Build Status Coverage Status

Usage

import { ReadableFileWriter } from 'readable-file-writer'
import request = require('request')
import express = require('express')

const app = express()
app.get('/', (req, res) => {
    // Stream a file from an HTTP server to disk
    const writer = new ReadableFileWriter('movie.mp4')
    request('http://foo.com/movie.mp4').pipe(writer)

    // Stream the file to the client at the same time
    writer.createReadStream().pipe(res)
})
app.listen(3000)

API

export interface Options
{
    bufferSize: number;
}

export interface ReadStreamOptions
{
    highWaterMark: number;
}

class ReadableFileWriter extends stream.Writable
{
    constructor(
        path: string,
        options?: Options
    );

    readonly path: string;

    createReadStream(
        options?: ReadStreamOptions
    ): NodeJS.ReadableStream;
}

Options

bufferSize - total maximum amount of memory (in bytes) that can be used for buffering transferred data. Default value is 1MB.

The memory buffer contains last chunks of data that went through the writing pipeline.

Readers always try to read from the memory buffer first. If the memory buffer is big enough or the reading pipeline is fast enough the streaming is done completely from the memory buffer.

ReadableFileWriter's events

  • open
  • close
  • error

ReadableFileWriter.createReadStream

Creates a readable stream. Readable streams can be created and used at any time, even if the writing pipeline is finished and the instance of ReadableFileWriter is destroyed.

Any number of readable streams can be created.

highWaterMark - this value is passed to all calls to fs.createReadStream that ReadableFileWriter makes under the hood during the streaming. Default value is 128KB.

Error handling

Clients should listen to error events on the instance of ReadableFileWriter and listen to error events on all created readable streams.

ReadableFileWriter propagates errors from the writing pipeline to all reading pipelines. It allows clients to gracefuly stop reading pipelines without leaking resources.

Installation

npm install readable-file-writer

or

yarn add readable-file-writer

An additional installation step is required if your project is written in Typescript. Typings for the readable-stream module are not installed automatically. You have to install them manually using either option 1 or 2:

  • Option 1: install typings using npm or yarn. There is no standard @types/readable-stream right now but it may be added in the future;

  • Option 2: manually add typings from this module to your tsconfig.json:

    "include": [
        "./node_modules/readable-file-writer/types/readable-stream.d.ts"
    ]

Copyright © 2018 Sergei Kogan. Licensed under The MIT license.