This commit is contained in:
chrosey
2017-09-13 07:52:34 +02:00
parent a1f16c37f4
commit 2340b0226b
24621 changed files with 2912161 additions and 149 deletions
+45
View File
@@ -0,0 +1,45 @@
'use strict';
const fs = require('fs');
const execa = require('execa');
const pFinally = require('p-finally');
const pify = require('pify');
const rimraf = require('rimraf');
const tempfile = require('tempfile');
const fsP = pify(fs);
const rmP = pify(rimraf);
const input = Symbol('inputPath');
const output = Symbol('outputPath');
module.exports = opts => {
opts = Object.assign({}, opts);
if (!Buffer.isBuffer(opts.input)) {
return Promise.reject(new Error('Input is required'));
}
if (typeof opts.bin !== 'string') {
return Promise.reject(new Error('Binary is required'));
}
if (!Array.isArray(opts.args)) {
return Promise.reject(new Error('Arguments are required'));
}
const inputPath = tempfile();
const outputPath = tempfile();
opts.args = opts.args.map(x => x === input ? inputPath : x === output ? outputPath : x);
const promise = fsP.writeFile(inputPath, opts.input)
.then(() => execa(opts.bin, opts.args))
.then(() => fsP.readFile(outputPath));
return pFinally(promise, () => Promise.all([
rmP(inputPath),
rmP(outputPath)
]));
};
module.exports.input = input;
module.exports.output = output;
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Kevin Mårtensson <kevinmartensson@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+112
View File
@@ -0,0 +1,112 @@
{
"_args": [
[
{
"raw": "exec-buffer@^3.0.0",
"scope": null,
"escapedName": "exec-buffer",
"name": "exec-buffer",
"rawSpec": "^3.0.0",
"spec": ">=3.0.0 <4.0.0",
"type": "range"
},
"c:\\xampp\\htdocs\\laravel\\node_modules\\imagemin-gifsicle"
]
],
"_from": "exec-buffer@>=3.0.0 <4.0.0",
"_id": "exec-buffer@3.1.0",
"_inCache": true,
"_location": "/exec-buffer",
"_nodeVersion": "6.9.1",
"_npmOperationalInternal": {
"host": "packages-18-east.internal.npmjs.com",
"tmp": "tmp/exec-buffer-3.1.0.tgz_1477346833189_0.4060145951807499"
},
"_npmUser": {
"name": "kevva",
"email": "kevinmartensson@gmail.com"
},
"_npmVersion": "3.10.6",
"_phantomChildren": {},
"_requested": {
"raw": "exec-buffer@^3.0.0",
"scope": null,
"escapedName": "exec-buffer",
"name": "exec-buffer",
"rawSpec": "^3.0.0",
"spec": ">=3.0.0 <4.0.0",
"type": "range"
},
"_requiredBy": [
"/imagemin-gifsicle",
"/imagemin-mozjpeg",
"/imagemin-optipng",
"/imagemin-pngquant"
],
"_resolved": "https://registry.npmjs.org/exec-buffer/-/exec-buffer-3.1.0.tgz",
"_shasum": "851b46d062fca9bcbc6ff8781693e28e8da80402",
"_shrinkwrap": null,
"_spec": "exec-buffer@^3.0.0",
"_where": "c:\\xampp\\htdocs\\laravel\\node_modules\\imagemin-gifsicle",
"author": {
"name": "Kevin Mårtensson",
"email": "kevinmartensson@gmail.com",
"url": "https://github.com/kevva"
},
"bugs": {
"url": "https://github.com/kevva/exec-buffer/issues"
},
"dependencies": {
"execa": "^0.5.0",
"p-finally": "^1.0.0",
"pify": "^2.3.0",
"rimraf": "^2.5.4",
"tempfile": "^1.0.0"
},
"description": "Run a buffer through a child process",
"devDependencies": {
"ava": "*",
"gifsicle": "^2.0.0",
"is-gif": "^1.0.0",
"path-exists": "^3.0.0",
"xo": "*"
},
"directories": {},
"dist": {
"shasum": "851b46d062fca9bcbc6ff8781693e28e8da80402",
"tarball": "https://registry.npmjs.org/exec-buffer/-/exec-buffer-3.1.0.tgz"
},
"engines": {
"node": ">=4"
},
"files": [
"index.js"
],
"gitHead": "7733dd0cd3d4d46301a367a424dd9a2b395d61b2",
"homepage": "https://github.com/kevva/exec-buffer#readme",
"keywords": [
"buffer",
"exec"
],
"license": "MIT",
"maintainers": [
{
"name": "kevva",
"email": "kevinmartensson@gmail.com"
}
],
"name": "exec-buffer",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/kevva/exec-buffer.git"
},
"scripts": {
"test": "xo && ava"
},
"version": "3.1.0",
"xo": {
"esnext": true
}
}
+66
View File
@@ -0,0 +1,66 @@
# exec-buffer [![Build Status](http://img.shields.io/travis/kevva/exec-buffer.svg?style=flat)](https://travis-ci.org/kevva/exec-buffer)
> Run a buffer through a child process
## Install
```
$ npm install --save exec-buffer
```
## Usage
```js
const fs = require('fs');
const execBuffer = require('exec-buffer');
const gifsicle = require('gifsicle').path;
execBuffer({
input: fs.readFileSync('test.gif'),
bin: gifsicle,
args: ['-o', execBuffer.output, execBuffer.input]
}).then(data => {
console.log(data);
//=> <Buffer 47 49 46 38 37 61 ...>
});
```
## API
### execBuffer(options)
#### options
##### input
Type: `buffer`
The `buffer` to be ran through the child process.
##### bin
Type: `string`
Path to the binary.
##### args
Type: `array`
Arguments to run the binary with.
### execBuffer.input
Returns a temporary path to where the input file will be written.
### execBuffer.output
Returns a temporary path to where the output file will be written.
## License
MIT © [Kevin Mårtensson](https://github.com/kevva)