Giter Club home page Giter Club logo

mute-stream's Introduction

mute-stream

Bytes go in, but they don't come out (when muted).

This is a basic pass-through stream, but when muted, the bytes are silently dropped, rather than being passed through.

Usage

const MuteStream = require('mute-stream')

const ms = new MuteStream(options)

ms.pipe(process.stdout)
ms.write('foo') // writes 'foo' to stdout
ms.mute()
ms.write('bar') // does not write 'bar'
ms.unmute()
ms.write('baz') // writes 'baz' to stdout

// can also be used to mute incoming data
const ms = new MuteStream()
input.pipe(ms)

ms.on('data', function (c) {
  console.log('data: ' + c)
})

input.emit('data', 'foo') // logs 'foo'
ms.mute()
input.emit('data', 'bar') // does not log 'bar'
ms.unmute()
input.emit('data', 'baz') // logs 'baz'

Options

All options are optional.

  • replace Set to a string to replace each character with the specified string when muted. (So you can show **** instead of the password, for example.)

  • prompt If you are using a replacement char, and also using a prompt with a readline stream (as for a Password: ***** input), then specify what the prompt is so that backspace will work properly. Otherwise, pressing backspace will overwrite the prompt with the replacement character, which is weird.

ms.mute()

Set muted to true. Turns .write() into a no-op.

ms.unmute()

Set muted to false

ms.isTTY

True if the pipe destination is a TTY, or if the incoming pipe source is a TTY.

Other stream methods...

The other standard readable and writable stream methods are all available. The MuteStream object acts as a facade to its pipe source and destination.

mute-stream's People

Contributors

alex-seville avatar dependabot[bot] avatar github-actions[bot] avatar isaacs avatar limulus avatar lukekarrys avatar nlf avatar wraithgar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mute-stream's Issues

New admin?

@isaacs I know you are busy running npm, but can you add an admin to this repo a new collaborator for the npm package to publish fixes? I'm willing to be that admin, but happy if you nominate anyone else. Currently #3 is revealing itself in a dependency 3 levels down in my project. My project uses prompt which uses read (another of your packages) which uses mute-stream.

I think this might be representative of an emerging issue with NPM itself. What happens to packages that are essentially abandonware? mute-stream is a good package, it just needs a small PR merged in and a patch released. What is the @npm / NPM Inc approved solution for this?
Current solutions that come to mind feel bad:

  • Pollute the NPM registry namespace with new packages mute-stream-2, mute-stream-active, mute-stream-active-2 and let new users suffer the folly of relying on the package with the obvious name that is no longer maintained?
  • Fork every abandoned project to merge a few patches and include my fork repo as a dependency in my package.json. That removes all the benefit of the NPM registry. It also creates overhead and I have to go scouting through forks to find other bug fixes to merge into my fork which limits the benefit of having a registry. This solution fixes my immediate problem but doesn't help the community. In my particular case I have to fork two levels of projects to fix my issue.
  • Fork and publish under a scoped package? This cheats anyone else from benefitting from my work since it will be impossible to find via search.

These all feel bad because they create a lot of duplicated work by anyone who needs to fix a package and add confusion to the system. Maybe there should be some way for the community to vote on which repo an NPM package points to or a way to nominate a replacement repo if an owner becomes unresponsive?

0.9.6-pre

Partially works? I noticed read having problems when prompting user input. It wouldn't show the prompt, but you could still get a canceled error and input text (even though you couldn't see it). Commented out the mute-stream in read, and everything went back to working as it should.

Haven't had a chance to dig in and find exactly what it is, but bnoordhuis said that streams2 finally hit. Sure it's due to that.

Reveals characters with ANSI escape sequences

When using the read module in silent mode with an ANSI formatted prompt and setting a replace character upon the backspace keypress event the replace character is no longer respected, ie, the plain text is displayed on screen.

Without ANSI escape sequences this issue is not present.

I tracked this down to the write method and have implemented a fix, within the ANSI conditional clause (https://github.com/isaacs/mute-stream/blob/master/mute.js#L103) I added:

if(c.indexOf(this._prompt) === 0) {
  var text = c.replace(this._prompt, '');
  text = text.replace(/./g, this.replace);
  c = this._prompt + text;
}

I am using a modified version of the read module which allows passing the unformatted prompt length when calling ReadlineInterface.setPrompt() (nodejs/node-v0.x-archive#3860).

node --version => v0.10.29

The patched version of mute-stream is here:

https://github.com/freeformsystems/cli-input/blob/master/lib/mute.js

Interested in a pull request?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.