Skip to content

Commit

Permalink
Merge c264c6c into 5b97df6
Browse files Browse the repository at this point in the history
  • Loading branch information
nknapp committed Jan 21, 2017
2 parents 5b97df6 + c264c6c commit 9b2be53
Show file tree
Hide file tree
Showing 20 changed files with 875 additions and 493 deletions.
34 changes: 34 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# .editorconfig <https://github.com/tunnckoCore/dotfiles>
#
# Copyright (c) 2015 Charlike Mike Reagent, contributors.
# Released under the MIT license.
#

root = true

[*]
indent_style = space
charset = utf-8
end_of_line = lf
insert_final_newline = false
trim_trailing_whitespace = false

[*.{js,php}]
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.{php,html}]
indent_size = 4

[*.{json,cson,yml,yaml,html,md,jade,css,stylus}]
indent_size = 2

[Makefile]
indent_size = 2
indent_style = tab

[.*rc]
indent_size = 2
indent_style = space
trim_trailing_whitespace = true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.iml
node_modules
/coverage/
44 changes: 44 additions & 0 deletions .thought/partials/api.md.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Functions
---------
#### `ps.spawn(command, [args], [options])`
For details about function arguments please refer to the api documentation of
[child_process.spawn(command, [args], [options])](http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options)
#### `ps.exec(command, [options], callback)`
For details about function arguments please refer to the api documentation of
[child_process.exec(command, [options], callback)](http://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback)
#### `ps.execFile(file, [args], [options], [callback])`
For details about function arguments please refer to the api documentation of
[child_process.execFile(file, [args], [options], [callback])](http://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback)
#### `ps.factory(useTmpIn, useTmpOut, callback)`
This function uses the provided callback to connect input and output of the resulting stream. `useTmpIn` and `useTmpOut` are booleans that define which
parts of the stream temp should use temp files.
`callback` has the signature `function(input, output, callback)`. "input" and "output" are either streams of paths of temporary files. The callback must
be called when data is available for output. If "tmpUseOut" is `false`, this can be called immediately. It "tmpUseOut" is `true` it must be called, when the
output tempfile has completely been written to.
Changing the placeholder tokens
-------------------------------
The tokens `<INPUT>` and `<OUTPUT>` can be changed:
{{example 'examples/placeholders.js'}}
Events
------
Process errors (such as not finding the executable file) are emitted on the resulting stream as `'error'` event.
The `'started'` event is emitted when the is started. Its first argument is the child-process object, second and
third arguments are the `command` and `args` passed to `ps.exec`, `ps.spawn` or `ps.execFile`), but with the
placeholders resolved to the their actual temporary files.
{{example 'examples/events.js'}}
29 changes: 29 additions & 0 deletions .thought/partials/overview.md.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Motivation
----------
The goal of this small package is to provide a interface for streaming data to
and from child-processes. It may be possible to stream data to a process via stdout
and read the result from stdin, but it may also be necessary to store the data in a
temporary file and provide the filename to the process as argument.
A concrete example is ffmpeg: It is possible to encode webm-videos to a stream,
but h264 must always be stored in a temporary file first. On the other hand in some cases
[it is not possible to stream data into ffmpeg](http://superuser.com/questions/822500/pipe-issue-with-ffmpeg),
so data must be stored in a temporary file prior to calling ffmpeg.
Overview
--------
ProcessStreams provides the methods `exec`, `execFile` and `spawn` from the `child_process` with the same arguments.
The return value however is always a through-stream. The command line arguments are examined for occurences of
the strings `<INPUT>` and `<OUTPUT>`.
* If `<INPUT>` is present, the stream input is piped into a temporary file and `<INPUT>` is replaced by its filename.
* If `<OUTPUT>` is present, it is replaced by the name of a temporary file and the contents of this file is
used as stream output for the resulting stream.
* If `<INPUT>` or `<OUTPUT>` are not present, the stream input is directly piped to the child processes stdin
(or the child processes stdout is piped to the stream output).
Temporary files are always deleted when no longer needed.
12 changes: 12 additions & 0 deletions .thought/partials/usage.md.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Simple Examples
--------
The following examples actually only pipes data to stdout, but via child processes with different temp-file options.
{{example 'examples/example.js'}}
Output:
{{{exec 'node example.js' cwd='examples/'}}}
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
sudo: false
language: node_js
node_js:
- '0.10'
- '0.12'
- '4'
- '5'
- '6'
- '7'
before_script:
- npm install standard
- standard
script:
- npm install istanbul
- istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- test
after_script:
- npm install coveralls
- cat ./coverage/lcov.info | coveralls
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Changes
--------
#### 1.0.1

* Testcase-fixes for iojs 1.2 and node 0.12
* Changed some dependencies to stable versions of other packages

#### 1.0.0

* There are no API changes in this version, but I have decided that the API should be stable now. Thus, version 1.0.0

#### 0.4.5

* All testcases should now run after `npm install`. All test-data is provided in dependencies (even for testECONRESET.js).
`package.json` is now complete, the README updated.

#### 0.4.4

* Added license information to package.json

#### 0.4.3

* Fixed error handling for `exec` and `execFile`
* Callback for `exec` and `execFile` is now forwarded to `child_process`
at the correct location, so that callbacks actually get called.

#### 0.4.2
* When using no in-tempfile, it may happen that the command (e.g. 'head -2') close the input stream before it is
completely read. This may result in a `EPIPE` or `ECONNRESET` but is not an actual error, since the output is
still correct. This error does not cause an `error`-event anymore, but an `input-closed` event.

56 changes: 56 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## Contributing

Contributions and feedback are always welcome. The expected procedure is the following:

### Bugs, Features and Feedback

* Please, create github issues for **feature-requests**, **bug reports**.
* Feel free to open issues for **questions and problems you have**, even if they are not bugs
or feature requests.
* You may even open an issue just to say you like the project.
* For small changes, such as **typo and formatting corrections**, you can immediately
create a pull-request. You can use the github web-interface, but keep in mind that most of the documentation
is created with Thought, so you should change the template in the `.thought` directory or change the default
templates in [the thought project](https://github.com/nknapp/thought/tree/master/handlebars).
* If you have an idea for a **new feature** that you would like to implement, please **open an issue** first and ask
for feedback. Maybe someone else has a similar problem and different ideas.
* If you encounter a bug you can submit a **pull-request for a failing unit test**, you should then also open an issue
for the bug.
* Before making a pull-request, make sure that you commit corresponds to the coding-style. You can do this by
running `npm test`.

**People submitting relevant contributions will be granted commit access to the repository.**


### Coding style

[![standard][standard-image]][standard-url]

This repository uses [`standard`][standard-url] to maintain code style and consistency,
and to avoid style arguments. You can run `npm run format` to apply the coding-style, but
you may need to fix some things manually. Make sure to use the latest version of `standard`.


### Installing & Testing

You can fork and clone the repo from github. Run

* Run `npm install` to install all the dependencies needed to build and run the project.
* Run `npm test` to run unit tests and validate the `standard` coding-style.
* Run `npm run thought` to generate the README.md and other markdown files in the repository.

It is intentional to don't have `standard`, `thought`, `istanbul` and `coveralls` in the devDependencies.
`standard` is a rather large package which you would not want to have copied into the `node_modules`-folder
of each of your projects.

Instead, the `pretest`- and `preformat`-scripts ensure that `standard` and `thought` are installed globally.
If you are not allowed to install packages globally, please raise an issue, so that we can try to find a solution.


### About this text

This text is part of the [Thought](https://github.com/nknapp/thought)-project. If you have any suggestions or wishes
to change the text, please raise an issue there for discussion.

[standard-image]: https://cdn.rawgit.com/feross/standard/master/badge.svg
[standard-url]: https://github.com/feross/standard

0 comments on commit 9b2be53

Please sign in to comment.