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

smart-pipe

v1.0.1

Published

Consistent STDIN piping, cross platform

Downloads

5

Readme

node-smart-pipe Travis-CI.org Build Status Coveralls.io Coverage Rating

Wrap STDIN buffers for programs that don't directly support stdin

Example

The following work cross-platform.

Asynchronous

var smartPipe = require('smart-pipe');
var exec = require('child_process').exec;

var buffer = new Buffer([1, 2, 3, 4]);
var piped = smartPipe(buffer);

var cmd = piped.command + 'xxd ' + piped.file;

var proc = exec(cmd, function(err, stdout, stderr) {
	console.log(stdout);
	piped.clean();
});

proc.stdin.write(piped.buffer);
proc.stdin.end();

Synchronous

var smartPipe = require('smart-pipe');
var exec = require('child_process').execSync;

var buffer = new Buffer([1, 2, 3, 4]);
var piped = smartPipe(buffer);

var cmd = piped.command + 'xxd ' + piped.file;

var result = exec(cmd, {input: piped.buffer});
console.log(result.toString());
piped.clean();

Explanation

You might be wondering, this seems really overkill.

  • Why do I even need this module? Because different platforms handle piping differently. Some platforms (like Windows) don't handle it at all. This module identifies the correct way to pipe information to "stdin" through the use of file descriptors (file paths).
  • Does this change the syntax of my commands? Slightly; you will need to use the filename version of the command. Whereas you would normally just pipe (i.e. echo hello | cat) you'll need to use the filename syntax (i.e. cat some_file.txt). This is because we pass the STDIN file descriptor as input.
  • Does this work on windows? Sure does; On Windows, since there is only a quasi-STDIN at best, we write the buffer to a temporary file first and that becomes the filename.
  • Why does this require a native injection on Linux? This issue explains a bit better, but essentially Node on Linux uses unix sockets to communicate with stdin of the child process instead of file descriptors. The native module handles this and performs small, cheap middleware operations upon opening the "file".
  • What's up with prefixing my commands? As per the last question, this prefix will have the LD_PRELOAD information on Linux, and be completely blank on other platforms.
  • Why do I need to call clean()? This is mainly on windows, but if a temporary file was written (on a platform that doesn't fully support STDIN), this will clean it. If you choose not to call .clean(), temporary files will be purged upon the exit of Node.

License

Licensed under the MIT License. You can find a copy of it in LICENSE.