Giter VIP home page Giter VIP logo

posix-cat's Introduction

posix-cat ๐Ÿˆ

A POSIX-like cat in JavaScript.

NPM

build status Build status NPM version

Sauce Test Status

CLI

echo "// before" | cat one.js two.js three.js > output.js

API

var Cat = require('posix-cat')

var cat = new Cat(argv)

Returns a transform stream. argv can be:

  • _: An array of arguments of file paths to concat; such as cat one.js two.js three.js
  • fs: Override the file system with a node/io compatible fs.
  • u: Write bytes without buffering.

license

(c) 2015 Kyle Robinson Young. MIT License

posix-cat's People

Contributors

es128 avatar shama avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

es128

posix-cat's Issues

Support '-' argument for stdin

It would be great if cat could support - as an argument to denote stdin as specified by SUSv3.

This would allow users to put a header/footer around stdin using cat as follows:

$ cat header - footer

Thanks,
Kevin

Should not buffer entire input

I found it very unexpected that cat would buffer its entire input before writing anything to stdout. Although buffering behavior is unspecified in SUSv3 (other than -u disabling any buffering that may be present), I am not aware of any other cat implementations which buffer all input. GNU cat ignores -u and always operates unbuffered. Most of the other implementations I've seen use it to disable output buffering by the standard library. Is there a reason that cat buffers all of its input (possibly GB worth) before writing any?

Thanks,
Kevin

Redirecting file to stdin results in TypeError

[Note: This is the first of several issues. I'm happy to send PRs for some/all of these, but most need some discussion first.]

When running cat with stdin redirected from a file yields the following result:

$ ./bin/cat < ./index.js 
/tmp/posix-cat/bin/cat:9
cat.on('end', process.stdin.end.bind(process.stdin))
                               ^

TypeError: Cannot read property 'bind' of undefined
    at Object.<anonymous> (/media/linuxdata/kevin/tmp/posix-cat/bin/cat:9:32)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:134:18)
    at node.js:962:3

This is because process.stdin is tty.ReadStream when stdin is a TTY and fs.ReadStream when it is a file.

Do you recall the reason for calling .end() here?

Thanks,
Kevin

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.