Spaces:
Paused
Paused
Upload folder using huggingface_hub (part 8)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- node_modules/cli-width/package.json +40 -0
- node_modules/color-convert/CHANGELOG.md +54 -0
- node_modules/color-convert/LICENSE +21 -0
- node_modules/color-convert/README.md +68 -0
- node_modules/color-convert/conversions.js +839 -0
- node_modules/color-convert/index.js +81 -0
- node_modules/color-convert/package.json +48 -0
- node_modules/color-convert/route.js +97 -0
- node_modules/combined-stream/License +19 -0
- node_modules/combined-stream/Readme.md +138 -0
- node_modules/combined-stream/lib/combined_stream.js +208 -0
- node_modules/combined-stream/package.json +25 -0
- node_modules/combined-stream/yarn.lock +17 -0
- node_modules/component-emitter/LICENSE +24 -0
- node_modules/component-emitter/Readme.md +74 -0
- node_modules/component-emitter/index.js +175 -0
- node_modules/component-emitter/package.json +28 -0
- node_modules/compress-commons/CHANGELOG.md +67 -0
- node_modules/compress-commons/LICENSE +22 -0
- node_modules/compress-commons/README.md +25 -0
- node_modules/compress-commons/lib/archivers/archive-entry.js +16 -0
- node_modules/compress-commons/lib/archivers/archive-output-stream.js +117 -0
- node_modules/compress-commons/lib/archivers/zip/constants.js +71 -0
- node_modules/compress-commons/lib/archivers/zip/general-purpose-bit.js +101 -0
- node_modules/compress-commons/lib/archivers/zip/unix-stat.js +53 -0
- node_modules/compress-commons/lib/archivers/zip/util.js +74 -0
- node_modules/compress-commons/lib/archivers/zip/zip-archive-entry.js +413 -0
- node_modules/compress-commons/lib/archivers/zip/zip-archive-output-stream.js +437 -0
- node_modules/compress-commons/lib/compress-commons.js +13 -0
- node_modules/compress-commons/lib/util/index.js +30 -0
- node_modules/compress-commons/package.json +45 -0
- node_modules/concat-map/.travis.yml +4 -0
- node_modules/concat-map/LICENSE +18 -0
- node_modules/concat-map/README.markdown +62 -0
- node_modules/concat-map/example/map.js +6 -0
- node_modules/concat-map/index.js +13 -0
- node_modules/concat-map/package.json +43 -0
- node_modules/concat-map/test/map.js +39 -0
- node_modules/concat-stream/LICENSE +24 -0
- node_modules/concat-stream/index.js +144 -0
- node_modules/concat-stream/package.json +55 -0
- node_modules/concat-stream/readme.md +102 -0
- node_modules/content-disposition/HISTORY.md +60 -0
- node_modules/content-disposition/LICENSE +22 -0
- node_modules/content-disposition/README.md +142 -0
- node_modules/content-disposition/index.js +458 -0
- node_modules/content-disposition/package.json +44 -0
- node_modules/content-type/HISTORY.md +29 -0
- node_modules/content-type/LICENSE +22 -0
- node_modules/content-type/README.md +94 -0
node_modules/cli-width/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "cli-width",
|
| 3 |
+
"version": "4.1.0",
|
| 4 |
+
"description": "Get stdout window width, with two fallbacks, tty and then a default.",
|
| 5 |
+
"main": "index.js",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"test": "node test | tspec",
|
| 8 |
+
"coverage": "nyc node test | tspec",
|
| 9 |
+
"coveralls": "npm run coverage -s && coveralls < coverage/lcov.info",
|
| 10 |
+
"release": "standard-version"
|
| 11 |
+
},
|
| 12 |
+
"repository": {
|
| 13 |
+
"type": "git",
|
| 14 |
+
"url": "git@github.com:knownasilya/cli-width.git"
|
| 15 |
+
},
|
| 16 |
+
"author": "Ilya Radchenko <knownasilya@gmail.com>",
|
| 17 |
+
"license": "ISC",
|
| 18 |
+
"bugs": {
|
| 19 |
+
"url": "https://github.com/knownasilya/cli-width/issues"
|
| 20 |
+
},
|
| 21 |
+
"homepage": "https://github.com/knownasilya/cli-width",
|
| 22 |
+
"engines": {
|
| 23 |
+
"node": ">= 12"
|
| 24 |
+
},
|
| 25 |
+
"devDependencies": {
|
| 26 |
+
"coveralls": "^3.1.1",
|
| 27 |
+
"nyc": "^15.1.0",
|
| 28 |
+
"standard-version": "^9.3.2",
|
| 29 |
+
"tap-spec": "^5.0.0",
|
| 30 |
+
"tape": "^5.5.2"
|
| 31 |
+
},
|
| 32 |
+
"volta": {
|
| 33 |
+
"node": "12.22.11",
|
| 34 |
+
"npm": "8.5.5"
|
| 35 |
+
},
|
| 36 |
+
"files": [
|
| 37 |
+
"index.js",
|
| 38 |
+
"index.d.ts"
|
| 39 |
+
]
|
| 40 |
+
}
|
node_modules/color-convert/CHANGELOG.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1.0.0 - 2016-01-07
|
| 2 |
+
|
| 3 |
+
- Removed: unused speed test
|
| 4 |
+
- Added: Automatic routing between previously unsupported conversions
|
| 5 |
+
([#27](https://github.com/Qix-/color-convert/pull/27))
|
| 6 |
+
- Removed: `xxx2xxx()` and `xxx2xxxRaw()` functions
|
| 7 |
+
([#27](https://github.com/Qix-/color-convert/pull/27))
|
| 8 |
+
- Removed: `convert()` class
|
| 9 |
+
([#27](https://github.com/Qix-/color-convert/pull/27))
|
| 10 |
+
- Changed: all functions to lookup dictionary
|
| 11 |
+
([#27](https://github.com/Qix-/color-convert/pull/27))
|
| 12 |
+
- Changed: `ansi` to `ansi256`
|
| 13 |
+
([#27](https://github.com/Qix-/color-convert/pull/27))
|
| 14 |
+
- Fixed: argument grouping for functions requiring only one argument
|
| 15 |
+
([#27](https://github.com/Qix-/color-convert/pull/27))
|
| 16 |
+
|
| 17 |
+
# 0.6.0 - 2015-07-23
|
| 18 |
+
|
| 19 |
+
- Added: methods to handle
|
| 20 |
+
[ANSI](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors) 16/256 colors:
|
| 21 |
+
- rgb2ansi16
|
| 22 |
+
- rgb2ansi
|
| 23 |
+
- hsl2ansi16
|
| 24 |
+
- hsl2ansi
|
| 25 |
+
- hsv2ansi16
|
| 26 |
+
- hsv2ansi
|
| 27 |
+
- hwb2ansi16
|
| 28 |
+
- hwb2ansi
|
| 29 |
+
- cmyk2ansi16
|
| 30 |
+
- cmyk2ansi
|
| 31 |
+
- keyword2ansi16
|
| 32 |
+
- keyword2ansi
|
| 33 |
+
- ansi162rgb
|
| 34 |
+
- ansi162hsl
|
| 35 |
+
- ansi162hsv
|
| 36 |
+
- ansi162hwb
|
| 37 |
+
- ansi162cmyk
|
| 38 |
+
- ansi162keyword
|
| 39 |
+
- ansi2rgb
|
| 40 |
+
- ansi2hsl
|
| 41 |
+
- ansi2hsv
|
| 42 |
+
- ansi2hwb
|
| 43 |
+
- ansi2cmyk
|
| 44 |
+
- ansi2keyword
|
| 45 |
+
([#18](https://github.com/harthur/color-convert/pull/18))
|
| 46 |
+
|
| 47 |
+
# 0.5.3 - 2015-06-02
|
| 48 |
+
|
| 49 |
+
- Fixed: hsl2hsv does not return `NaN` anymore when using `[0,0,0]`
|
| 50 |
+
([#15](https://github.com/harthur/color-convert/issues/15))
|
| 51 |
+
|
| 52 |
+
---
|
| 53 |
+
|
| 54 |
+
Check out commit logs for older releases
|
node_modules/color-convert/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2011-2016 Heather Arthur <fayearthur@gmail.com>
|
| 2 |
+
|
| 3 |
+
Permission is hereby granted, free of charge, to any person obtaining
|
| 4 |
+
a copy of this software and associated documentation files (the
|
| 5 |
+
"Software"), to deal in the Software without restriction, including
|
| 6 |
+
without limitation the rights to use, copy, modify, merge, publish,
|
| 7 |
+
distribute, sublicense, and/or sell copies of the Software, and to
|
| 8 |
+
permit persons to whom the Software is furnished to do so, subject to
|
| 9 |
+
the following conditions:
|
| 10 |
+
|
| 11 |
+
The above copyright notice and this permission notice shall be
|
| 12 |
+
included in all copies or substantial portions of the Software.
|
| 13 |
+
|
| 14 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 15 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 16 |
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 17 |
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
| 18 |
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
| 19 |
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
| 20 |
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 21 |
+
|
node_modules/color-convert/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# color-convert
|
| 2 |
+
|
| 3 |
+
[](https://travis-ci.org/Qix-/color-convert)
|
| 4 |
+
|
| 5 |
+
Color-convert is a color conversion library for JavaScript and node.
|
| 6 |
+
It converts all ways between `rgb`, `hsl`, `hsv`, `hwb`, `cmyk`, `ansi`, `ansi16`, `hex` strings, and CSS `keyword`s (will round to closest):
|
| 7 |
+
|
| 8 |
+
```js
|
| 9 |
+
var convert = require('color-convert');
|
| 10 |
+
|
| 11 |
+
convert.rgb.hsl(140, 200, 100); // [96, 48, 59]
|
| 12 |
+
convert.keyword.rgb('blue'); // [0, 0, 255]
|
| 13 |
+
|
| 14 |
+
var rgbChannels = convert.rgb.channels; // 3
|
| 15 |
+
var cmykChannels = convert.cmyk.channels; // 4
|
| 16 |
+
var ansiChannels = convert.ansi16.channels; // 1
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
# Install
|
| 20 |
+
|
| 21 |
+
```console
|
| 22 |
+
$ npm install color-convert
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
# API
|
| 26 |
+
|
| 27 |
+
Simply get the property of the _from_ and _to_ conversion that you're looking for.
|
| 28 |
+
|
| 29 |
+
All functions have a rounded and unrounded variant. By default, return values are rounded. To get the unrounded (raw) results, simply tack on `.raw` to the function.
|
| 30 |
+
|
| 31 |
+
All 'from' functions have a hidden property called `.channels` that indicates the number of channels the function expects (not including alpha).
|
| 32 |
+
|
| 33 |
+
```js
|
| 34 |
+
var convert = require('color-convert');
|
| 35 |
+
|
| 36 |
+
// Hex to LAB
|
| 37 |
+
convert.hex.lab('DEADBF'); // [ 76, 21, -2 ]
|
| 38 |
+
convert.hex.lab.raw('DEADBF'); // [ 75.56213190997677, 20.653827952644754, -2.290532499330533 ]
|
| 39 |
+
|
| 40 |
+
// RGB to CMYK
|
| 41 |
+
convert.rgb.cmyk(167, 255, 4); // [ 35, 0, 98, 0 ]
|
| 42 |
+
convert.rgb.cmyk.raw(167, 255, 4); // [ 34.509803921568626, 0, 98.43137254901961, 0 ]
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
### Arrays
|
| 46 |
+
All functions that accept multiple arguments also support passing an array.
|
| 47 |
+
|
| 48 |
+
Note that this does **not** apply to functions that convert from a color that only requires one value (e.g. `keyword`, `ansi256`, `hex`, etc.)
|
| 49 |
+
|
| 50 |
+
```js
|
| 51 |
+
var convert = require('color-convert');
|
| 52 |
+
|
| 53 |
+
convert.rgb.hex(123, 45, 67); // '7B2D43'
|
| 54 |
+
convert.rgb.hex([123, 45, 67]); // '7B2D43'
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
## Routing
|
| 58 |
+
|
| 59 |
+
Conversions that don't have an _explicitly_ defined conversion (in [conversions.js](conversions.js)), but can be converted by means of sub-conversions (e.g. XYZ -> **RGB** -> CMYK), are automatically routed together. This allows just about any color model supported by `color-convert` to be converted to any other model, so long as a sub-conversion path exists. This is also true for conversions requiring more than one step in between (e.g. LCH -> **LAB** -> **XYZ** -> **RGB** -> Hex).
|
| 60 |
+
|
| 61 |
+
Keep in mind that extensive conversions _may_ result in a loss of precision, and exist only to be complete. For a list of "direct" (single-step) conversions, see [conversions.js](conversions.js).
|
| 62 |
+
|
| 63 |
+
# Contribute
|
| 64 |
+
|
| 65 |
+
If there is a new model you would like to support, or want to add a direct conversion between two existing models, please send us a pull request.
|
| 66 |
+
|
| 67 |
+
# License
|
| 68 |
+
Copyright © 2011-2016, Heather Arthur and Josh Junon. Licensed under the [MIT License](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int-disable no-mixed-operators */
|
| 3 |
+
const cssKeywords = require('color-name');
|
| 4 |
+
|
| 5 |
+
// NOTE: conversions should only return primitive values (i.e. arrays, or
|
| 6 |
+
// values that give correct `typeof` results).
|
| 7 |
+
// do not use box values types (i.e. Number(), String(), etc.)
|
| 8 |
+
|
| 9 |
+
const reverseKeywords = {};
|
| 10 |
+
for (const key of Object.keys(cssKeywords)) {
|
| 11 |
+
reverseKeywords[cssKeywords[key]] = key;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
const convert = {
|
| 15 |
+
rgb: {channels: 3, labels: 'rgb'},
|
| 16 |
+
hsl: {channels: 3, labels: 'hsl'},
|
| 17 |
+
hsv: {channels: 3, labels: 'hsv'},
|
| 18 |
+
hwb: {channels: 3, labels: 'hwb'},
|
| 19 |
+
cmyk: {channels: 4, labels: 'cmyk'},
|
| 20 |
+
xyz: {channels: 3, labels: 'xyz'},
|
| 21 |
+
lab: {channels: 3, labels: 'lab'},
|
| 22 |
+
lch: {channels: 3, labels: 'lch'},
|
| 23 |
+
hex: {channels: 1, labels: ['hex']},
|
| 24 |
+
keyword: {channels: 1, labels: ['keyword']},
|
| 25 |
+
ansi16: {channels: 1, labels: ['ansi16']},
|
| 26 |
+
ansi256: {channels: 1, labels: ['ansi256']},
|
| 27 |
+
hcg: {channels: 3, labels: ['h', 'c', 'g']},
|
| 28 |
+
apple: {channels: 3, labels: ['r16', 'g16', 'b16']},
|
| 29 |
+
gray: {channels: 1, labels: ['gray']}
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
module.exports = convert;
|
| 33 |
+
|
| 34 |
+
// Hide .channels and .labels properties
|
| 35 |
+
for (const model of Object.keys(convert)) {
|
| 36 |
+
if (!('channels' in convert[model])) {
|
| 37 |
+
throw new Error('missing channels property: ' + model);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
if (!('labels' in convert[model])) {
|
| 41 |
+
throw new Error('missing channel labels property: ' + model);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
if (convert[model].labels.length !== convert[model].channels) {
|
| 45 |
+
throw new Error('channel and label counts mismatch: ' + model);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
const {channels, labels} = convert[model];
|
| 49 |
+
delete convert[model].channels;
|
| 50 |
+
delete convert[model].labels;
|
| 51 |
+
Object.defineProperty(convert[model], 'channels', {value: channels});
|
| 52 |
+
Object.defineProperty(convert[model], 'labels', {value: labels});
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
convert.rgb.hsl = function (rgb) {
|
| 56 |
+
const r = rgb[0] / 255;
|
| 57 |
+
const g = rgb[1] / 255;
|
| 58 |
+
const b = rgb[2] / 255;
|
| 59 |
+
const min = Math.min(r, g, b);
|
| 60 |
+
const max = Math.max(r, g, b);
|
| 61 |
+
const delta = max - min;
|
| 62 |
+
let h;
|
| 63 |
+
let s;
|
| 64 |
+
|
| 65 |
+
if (max === min) {
|
| 66 |
+
h = 0;
|
| 67 |
+
} else if (r === max) {
|
| 68 |
+
h = (g - b) / delta;
|
| 69 |
+
} else if (g === max) {
|
| 70 |
+
h = 2 + (b - r) / delta;
|
| 71 |
+
} else if (b === max) {
|
| 72 |
+
h = 4 + (r - g) / delta;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
h = Math.min(h * 60, 360);
|
| 76 |
+
|
| 77 |
+
if (h < 0) {
|
| 78 |
+
h += 360;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
const l = (min + max) / 2;
|
| 82 |
+
|
| 83 |
+
if (max === min) {
|
| 84 |
+
s = 0;
|
| 85 |
+
} else if (l <= 0.5) {
|
| 86 |
+
s = delta / (max + min);
|
| 87 |
+
} else {
|
| 88 |
+
s = delta / (2 - max - min);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
return [h, s * 100, l * 100];
|
| 92 |
+
};
|
| 93 |
+
|
| 94 |
+
convert.rgb.hsv = function (rgb) {
|
| 95 |
+
let rdif;
|
| 96 |
+
let gdif;
|
| 97 |
+
let bdif;
|
| 98 |
+
let h;
|
| 99 |
+
let s;
|
| 100 |
+
|
| 101 |
+
const r = rgb[0] / 255;
|
| 102 |
+
const g = rgb[1] / 255;
|
| 103 |
+
const b = rgb[2] / 255;
|
| 104 |
+
const v = Math.max(r, g, b);
|
| 105 |
+
const diff = v - Math.min(r, g, b);
|
| 106 |
+
const diffc = function (c) {
|
| 107 |
+
return (v - c) / 6 / diff + 1 / 2;
|
| 108 |
+
};
|
| 109 |
+
|
| 110 |
+
if (diff === 0) {
|
| 111 |
+
h = 0;
|
| 112 |
+
s = 0;
|
| 113 |
+
} else {
|
| 114 |
+
s = diff / v;
|
| 115 |
+
rdif = diffc(r);
|
| 116 |
+
gdif = diffc(g);
|
| 117 |
+
bdif = diffc(b);
|
| 118 |
+
|
| 119 |
+
if (r === v) {
|
| 120 |
+
h = bdif - gdif;
|
| 121 |
+
} else if (g === v) {
|
| 122 |
+
h = (1 / 3) + rdif - bdif;
|
| 123 |
+
} else if (b === v) {
|
| 124 |
+
h = (2 / 3) + gdif - rdif;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
if (h < 0) {
|
| 128 |
+
h += 1;
|
| 129 |
+
} else if (h > 1) {
|
| 130 |
+
h -= 1;
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
return [
|
| 135 |
+
h * 360,
|
| 136 |
+
s * 100,
|
| 137 |
+
v * 100
|
| 138 |
+
];
|
| 139 |
+
};
|
| 140 |
+
|
| 141 |
+
convert.rgb.hwb = function (rgb) {
|
| 142 |
+
const r = rgb[0];
|
| 143 |
+
const g = rgb[1];
|
| 144 |
+
let b = rgb[2];
|
| 145 |
+
const h = convert.rgb.hsl(rgb)[0];
|
| 146 |
+
const w = 1 / 255 * Math.min(r, Math.min(g, b));
|
| 147 |
+
|
| 148 |
+
b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
|
| 149 |
+
|
| 150 |
+
return [h, w * 100, b * 100];
|
| 151 |
+
};
|
| 152 |
+
|
| 153 |
+
convert.rgb.cmyk = function (rgb) {
|
| 154 |
+
const r = rgb[0] / 255;
|
| 155 |
+
const g = rgb[1] / 255;
|
| 156 |
+
const b = rgb[2] / 255;
|
| 157 |
+
|
| 158 |
+
const k = Math.min(1 - r, 1 - g, 1 - b);
|
| 159 |
+
const c = (1 - r - k) / (1 - k) || 0;
|
| 160 |
+
const m = (1 - g - k) / (1 - k) || 0;
|
| 161 |
+
const y = (1 - b - k) / (1 - k) || 0;
|
| 162 |
+
|
| 163 |
+
return [c * 100, m * 100, y * 100, k * 100];
|
| 164 |
+
};
|
| 165 |
+
|
| 166 |
+
function comparativeDistance(x, y) {
|
| 167 |
+
/*
|
| 168 |
+
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
|
| 169 |
+
*/
|
| 170 |
+
return (
|
| 171 |
+
((x[0] - y[0]) ** 2) +
|
| 172 |
+
((x[1] - y[1]) ** 2) +
|
| 173 |
+
((x[2] - y[2]) ** 2)
|
| 174 |
+
);
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
convert.rgb.keyword = function (rgb) {
|
| 178 |
+
const reversed = reverseKeywords[rgb];
|
| 179 |
+
if (reversed) {
|
| 180 |
+
return reversed;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
let currentClosestDistance = Infinity;
|
| 184 |
+
let currentClosestKeyword;
|
| 185 |
+
|
| 186 |
+
for (const keyword of Object.keys(cssKeywords)) {
|
| 187 |
+
const value = cssKeywords[keyword];
|
| 188 |
+
|
| 189 |
+
// Compute comparative distance
|
| 190 |
+
const distance = comparativeDistance(rgb, value);
|
| 191 |
+
|
| 192 |
+
// Check if its less, if so set as closest
|
| 193 |
+
if (distance < currentClosestDistance) {
|
| 194 |
+
currentClosestDistance = distance;
|
| 195 |
+
currentClosestKeyword = keyword;
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
return currentClosestKeyword;
|
| 200 |
+
};
|
| 201 |
+
|
| 202 |
+
convert.keyword.rgb = function (keyword) {
|
| 203 |
+
return cssKeywords[keyword];
|
| 204 |
+
};
|
| 205 |
+
|
| 206 |
+
convert.rgb.xyz = function (rgb) {
|
| 207 |
+
let r = rgb[0] / 255;
|
| 208 |
+
let g = rgb[1] / 255;
|
| 209 |
+
let b = rgb[2] / 255;
|
| 210 |
+
|
| 211 |
+
// Assume sRGB
|
| 212 |
+
r = r > 0.04045 ? (((r + 0.055) / 1.055) ** 2.4) : (r / 12.92);
|
| 213 |
+
g = g > 0.04045 ? (((g + 0.055) / 1.055) ** 2.4) : (g / 12.92);
|
| 214 |
+
b = b > 0.04045 ? (((b + 0.055) / 1.055) ** 2.4) : (b / 12.92);
|
| 215 |
+
|
| 216 |
+
const x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
|
| 217 |
+
const y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
|
| 218 |
+
const z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
|
| 219 |
+
|
| 220 |
+
return [x * 100, y * 100, z * 100];
|
| 221 |
+
};
|
| 222 |
+
|
| 223 |
+
convert.rgb.lab = function (rgb) {
|
| 224 |
+
const xyz = convert.rgb.xyz(rgb);
|
| 225 |
+
let x = xyz[0];
|
| 226 |
+
let y = xyz[1];
|
| 227 |
+
let z = xyz[2];
|
| 228 |
+
|
| 229 |
+
x /= 95.047;
|
| 230 |
+
y /= 100;
|
| 231 |
+
z /= 108.883;
|
| 232 |
+
|
| 233 |
+
x = x > 0.008856 ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116);
|
| 234 |
+
y = y > 0.008856 ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116);
|
| 235 |
+
z = z > 0.008856 ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116);
|
| 236 |
+
|
| 237 |
+
const l = (116 * y) - 16;
|
| 238 |
+
const a = 500 * (x - y);
|
| 239 |
+
const b = 200 * (y - z);
|
| 240 |
+
|
| 241 |
+
return [l, a, b];
|
| 242 |
+
};
|
| 243 |
+
|
| 244 |
+
convert.hsl.rgb = function (hsl) {
|
| 245 |
+
const h = hsl[0] / 360;
|
| 246 |
+
const s = hsl[1] / 100;
|
| 247 |
+
const l = hsl[2] / 100;
|
| 248 |
+
let t2;
|
| 249 |
+
let t3;
|
| 250 |
+
let val;
|
| 251 |
+
|
| 252 |
+
if (s === 0) {
|
| 253 |
+
val = l * 255;
|
| 254 |
+
return [val, val, val];
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
if (l < 0.5) {
|
| 258 |
+
t2 = l * (1 + s);
|
| 259 |
+
} else {
|
| 260 |
+
t2 = l + s - l * s;
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
const t1 = 2 * l - t2;
|
| 264 |
+
|
| 265 |
+
const rgb = [0, 0, 0];
|
| 266 |
+
for (let i = 0; i < 3; i++) {
|
| 267 |
+
t3 = h + 1 / 3 * -(i - 1);
|
| 268 |
+
if (t3 < 0) {
|
| 269 |
+
t3++;
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
if (t3 > 1) {
|
| 273 |
+
t3--;
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
if (6 * t3 < 1) {
|
| 277 |
+
val = t1 + (t2 - t1) * 6 * t3;
|
| 278 |
+
} else if (2 * t3 < 1) {
|
| 279 |
+
val = t2;
|
| 280 |
+
} else if (3 * t3 < 2) {
|
| 281 |
+
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
| 282 |
+
} else {
|
| 283 |
+
val = t1;
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
rgb[i] = val * 255;
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
return rgb;
|
| 290 |
+
};
|
| 291 |
+
|
| 292 |
+
convert.hsl.hsv = function (hsl) {
|
| 293 |
+
const h = hsl[0];
|
| 294 |
+
let s = hsl[1] / 100;
|
| 295 |
+
let l = hsl[2] / 100;
|
| 296 |
+
let smin = s;
|
| 297 |
+
const lmin = Math.max(l, 0.01);
|
| 298 |
+
|
| 299 |
+
l *= 2;
|
| 300 |
+
s *= (l <= 1) ? l : 2 - l;
|
| 301 |
+
smin *= lmin <= 1 ? lmin : 2 - lmin;
|
| 302 |
+
const v = (l + s) / 2;
|
| 303 |
+
const sv = l === 0 ? (2 * smin) / (lmin + smin) : (2 * s) / (l + s);
|
| 304 |
+
|
| 305 |
+
return [h, sv * 100, v * 100];
|
| 306 |
+
};
|
| 307 |
+
|
| 308 |
+
convert.hsv.rgb = function (hsv) {
|
| 309 |
+
const h = hsv[0] / 60;
|
| 310 |
+
const s = hsv[1] / 100;
|
| 311 |
+
let v = hsv[2] / 100;
|
| 312 |
+
const hi = Math.floor(h) % 6;
|
| 313 |
+
|
| 314 |
+
const f = h - Math.floor(h);
|
| 315 |
+
const p = 255 * v * (1 - s);
|
| 316 |
+
const q = 255 * v * (1 - (s * f));
|
| 317 |
+
const t = 255 * v * (1 - (s * (1 - f)));
|
| 318 |
+
v *= 255;
|
| 319 |
+
|
| 320 |
+
switch (hi) {
|
| 321 |
+
case 0:
|
| 322 |
+
return [v, t, p];
|
| 323 |
+
case 1:
|
| 324 |
+
return [q, v, p];
|
| 325 |
+
case 2:
|
| 326 |
+
return [p, v, t];
|
| 327 |
+
case 3:
|
| 328 |
+
return [p, q, v];
|
| 329 |
+
case 4:
|
| 330 |
+
return [t, p, v];
|
| 331 |
+
case 5:
|
| 332 |
+
return [v, p, q];
|
| 333 |
+
}
|
| 334 |
+
};
|
| 335 |
+
|
| 336 |
+
convert.hsv.hsl = function (hsv) {
|
| 337 |
+
const h = hsv[0];
|
| 338 |
+
const s = hsv[1] / 100;
|
| 339 |
+
const v = hsv[2] / 100;
|
| 340 |
+
const vmin = Math.max(v, 0.01);
|
| 341 |
+
let sl;
|
| 342 |
+
let l;
|
| 343 |
+
|
| 344 |
+
l = (2 - s) * v;
|
| 345 |
+
const lmin = (2 - s) * vmin;
|
| 346 |
+
sl = s * vmin;
|
| 347 |
+
sl /= (lmin <= 1) ? lmin : 2 - lmin;
|
| 348 |
+
sl = sl || 0;
|
| 349 |
+
l /= 2;
|
| 350 |
+
|
| 351 |
+
return [h, sl * 100, l * 100];
|
| 352 |
+
};
|
| 353 |
+
|
| 354 |
+
// http://dev.w3.org/csswg/css-color/#hwb-to-rgb
|
| 355 |
+
convert.hwb.rgb = function (hwb) {
|
| 356 |
+
const h = hwb[0] / 360;
|
| 357 |
+
let wh = hwb[1] / 100;
|
| 358 |
+
let bl = hwb[2] / 100;
|
| 359 |
+
const ratio = wh + bl;
|
| 360 |
+
let f;
|
| 361 |
+
|
| 362 |
+
// Wh + bl cant be > 1
|
| 363 |
+
if (ratio > 1) {
|
| 364 |
+
wh /= ratio;
|
| 365 |
+
bl /= ratio;
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
const i = Math.floor(6 * h);
|
| 369 |
+
const v = 1 - bl;
|
| 370 |
+
f = 6 * h - i;
|
| 371 |
+
|
| 372 |
+
if ((i & 0x01) !== 0) {
|
| 373 |
+
f = 1 - f;
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
const n = wh + f * (v - wh); // Linear interpolation
|
| 377 |
+
|
| 378 |
+
let r;
|
| 379 |
+
let g;
|
| 380 |
+
let b;
|
| 381 |
+
/* eslint-disable max-statements-per-line,no-multi-spaces */
|
| 382 |
+
switch (i) {
|
| 383 |
+
default:
|
| 384 |
+
case 6:
|
| 385 |
+
case 0: r = v; g = n; b = wh; break;
|
| 386 |
+
case 1: r = n; g = v; b = wh; break;
|
| 387 |
+
case 2: r = wh; g = v; b = n; break;
|
| 388 |
+
case 3: r = wh; g = n; b = v; break;
|
| 389 |
+
case 4: r = n; g = wh; b = v; break;
|
| 390 |
+
case 5: r = v; g = wh; b = n; break;
|
| 391 |
+
}
|
| 392 |
+
/* eslint-enable max-statements-per-line,no-multi-spaces */
|
| 393 |
+
|
| 394 |
+
return [r * 255, g * 255, b * 255];
|
| 395 |
+
};
|
| 396 |
+
|
| 397 |
+
convert.cmyk.rgb = function (cmyk) {
|
| 398 |
+
const c = cmyk[0] / 100;
|
| 399 |
+
const m = cmyk[1] / 100;
|
| 400 |
+
const y = cmyk[2] / 100;
|
| 401 |
+
const k = cmyk[3] / 100;
|
| 402 |
+
|
| 403 |
+
const r = 1 - Math.min(1, c * (1 - k) + k);
|
| 404 |
+
const g = 1 - Math.min(1, m * (1 - k) + k);
|
| 405 |
+
const b = 1 - Math.min(1, y * (1 - k) + k);
|
| 406 |
+
|
| 407 |
+
return [r * 255, g * 255, b * 255];
|
| 408 |
+
};
|
| 409 |
+
|
| 410 |
+
convert.xyz.rgb = function (xyz) {
|
| 411 |
+
const x = xyz[0] / 100;
|
| 412 |
+
const y = xyz[1] / 100;
|
| 413 |
+
const z = xyz[2] / 100;
|
| 414 |
+
let r;
|
| 415 |
+
let g;
|
| 416 |
+
let b;
|
| 417 |
+
|
| 418 |
+
r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
|
| 419 |
+
g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
|
| 420 |
+
b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
|
| 421 |
+
|
| 422 |
+
// Assume sRGB
|
| 423 |
+
r = r > 0.0031308
|
| 424 |
+
? ((1.055 * (r ** (1.0 / 2.4))) - 0.055)
|
| 425 |
+
: r * 12.92;
|
| 426 |
+
|
| 427 |
+
g = g > 0.0031308
|
| 428 |
+
? ((1.055 * (g ** (1.0 / 2.4))) - 0.055)
|
| 429 |
+
: g * 12.92;
|
| 430 |
+
|
| 431 |
+
b = b > 0.0031308
|
| 432 |
+
? ((1.055 * (b ** (1.0 / 2.4))) - 0.055)
|
| 433 |
+
: b * 12.92;
|
| 434 |
+
|
| 435 |
+
r = Math.min(Math.max(0, r), 1);
|
| 436 |
+
g = Math.min(Math.max(0, g), 1);
|
| 437 |
+
b = Math.min(Math.max(0, b), 1);
|
| 438 |
+
|
| 439 |
+
return [r * 255, g * 255, b * 255];
|
| 440 |
+
};
|
| 441 |
+
|
| 442 |
+
convert.xyz.lab = function (xyz) {
|
| 443 |
+
let x = xyz[0];
|
| 444 |
+
let y = xyz[1];
|
| 445 |
+
let z = xyz[2];
|
| 446 |
+
|
| 447 |
+
x /= 95.047;
|
| 448 |
+
y /= 100;
|
| 449 |
+
z /= 108.883;
|
| 450 |
+
|
| 451 |
+
x = x > 0.008856 ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116);
|
| 452 |
+
y = y > 0.008856 ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116);
|
| 453 |
+
z = z > 0.008856 ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116);
|
| 454 |
+
|
| 455 |
+
const l = (116 * y) - 16;
|
| 456 |
+
const a = 500 * (x - y);
|
| 457 |
+
const b = 200 * (y - z);
|
| 458 |
+
|
| 459 |
+
return [l, a, b];
|
| 460 |
+
};
|
| 461 |
+
|
| 462 |
+
convert.lab.xyz = function (lab) {
|
| 463 |
+
const l = lab[0];
|
| 464 |
+
const a = lab[1];
|
| 465 |
+
const b = lab[2];
|
| 466 |
+
let x;
|
| 467 |
+
let y;
|
| 468 |
+
let z;
|
| 469 |
+
|
| 470 |
+
y = (l + 16) / 116;
|
| 471 |
+
x = a / 500 + y;
|
| 472 |
+
z = y - b / 200;
|
| 473 |
+
|
| 474 |
+
const y2 = y ** 3;
|
| 475 |
+
const x2 = x ** 3;
|
| 476 |
+
const z2 = z ** 3;
|
| 477 |
+
y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
|
| 478 |
+
x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
|
| 479 |
+
z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
|
| 480 |
+
|
| 481 |
+
x *= 95.047;
|
| 482 |
+
y *= 100;
|
| 483 |
+
z *= 108.883;
|
| 484 |
+
|
| 485 |
+
return [x, y, z];
|
| 486 |
+
};
|
| 487 |
+
|
| 488 |
+
convert.lab.lch = function (lab) {
|
| 489 |
+
const l = lab[0];
|
| 490 |
+
const a = lab[1];
|
| 491 |
+
const b = lab[2];
|
| 492 |
+
let h;
|
| 493 |
+
|
| 494 |
+
const hr = Math.atan2(b, a);
|
| 495 |
+
h = hr * 360 / 2 / Math.PI;
|
| 496 |
+
|
| 497 |
+
if (h < 0) {
|
| 498 |
+
h += 360;
|
| 499 |
+
}
|
| 500 |
+
|
| 501 |
+
const c = Math.sqrt(a * a + b * b);
|
| 502 |
+
|
| 503 |
+
return [l, c, h];
|
| 504 |
+
};
|
| 505 |
+
|
| 506 |
+
convert.lch.lab = function (lch) {
|
| 507 |
+
const l = lch[0];
|
| 508 |
+
const c = lch[1];
|
| 509 |
+
const h = lch[2];
|
| 510 |
+
|
| 511 |
+
const hr = h / 360 * 2 * Math.PI;
|
| 512 |
+
const a = c * Math.cos(hr);
|
| 513 |
+
const b = c * Math.sin(hr);
|
| 514 |
+
|
| 515 |
+
return [l, a, b];
|
| 516 |
+
};
|
| 517 |
+
|
| 518 |
+
convert.rgb.ansi16 = function (args, saturation = null) {
|
| 519 |
+
const [r, g, b] = args;
|
| 520 |
+
let value = saturation === null ? convert.rgb.hsv(args)[2] : saturation; // Hsv -> ansi16 optimization
|
| 521 |
+
|
| 522 |
+
value = Math.round(value / 50);
|
| 523 |
+
|
| 524 |
+
if (value === 0) {
|
| 525 |
+
return 30;
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
let ansi = 30
|
| 529 |
+
+ ((Math.round(b / 255) << 2)
|
| 530 |
+
| (Math.round(g / 255) << 1)
|
| 531 |
+
| Math.round(r / 255));
|
| 532 |
+
|
| 533 |
+
if (value === 2) {
|
| 534 |
+
ansi += 60;
|
| 535 |
+
}
|
| 536 |
+
|
| 537 |
+
return ansi;
|
| 538 |
+
};
|
| 539 |
+
|
| 540 |
+
convert.hsv.ansi16 = function (args) {
|
| 541 |
+
// Optimization here; we already know the value and don't need to get
|
| 542 |
+
// it converted for us.
|
| 543 |
+
return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
|
| 544 |
+
};
|
| 545 |
+
|
| 546 |
+
convert.rgb.ansi256 = function (args) {
|
| 547 |
+
const r = args[0];
|
| 548 |
+
const g = args[1];
|
| 549 |
+
const b = args[2];
|
| 550 |
+
|
| 551 |
+
// We use the extended greyscale palette here, with the exception of
|
| 552 |
+
// black and white. normal palette only has 4 greyscale shades.
|
| 553 |
+
if (r === g && g === b) {
|
| 554 |
+
if (r < 8) {
|
| 555 |
+
return 16;
|
| 556 |
+
}
|
| 557 |
+
|
| 558 |
+
if (r > 248) {
|
| 559 |
+
return 231;
|
| 560 |
+
}
|
| 561 |
+
|
| 562 |
+
return Math.round(((r - 8) / 247) * 24) + 232;
|
| 563 |
+
}
|
| 564 |
+
|
| 565 |
+
const ansi = 16
|
| 566 |
+
+ (36 * Math.round(r / 255 * 5))
|
| 567 |
+
+ (6 * Math.round(g / 255 * 5))
|
| 568 |
+
+ Math.round(b / 255 * 5);
|
| 569 |
+
|
| 570 |
+
return ansi;
|
| 571 |
+
};
|
| 572 |
+
|
| 573 |
+
convert.ansi16.rgb = function (args) {
|
| 574 |
+
let color = args % 10;
|
| 575 |
+
|
| 576 |
+
// Handle greyscale
|
| 577 |
+
if (color === 0 || color === 7) {
|
| 578 |
+
if (args > 50) {
|
| 579 |
+
color += 3.5;
|
| 580 |
+
}
|
| 581 |
+
|
| 582 |
+
color = color / 10.5 * 255;
|
| 583 |
+
|
| 584 |
+
return [color, color, color];
|
| 585 |
+
}
|
| 586 |
+
|
| 587 |
+
const mult = (~~(args > 50) + 1) * 0.5;
|
| 588 |
+
const r = ((color & 1) * mult) * 255;
|
| 589 |
+
const g = (((color >> 1) & 1) * mult) * 255;
|
| 590 |
+
const b = (((color >> 2) & 1) * mult) * 255;
|
| 591 |
+
|
| 592 |
+
return [r, g, b];
|
| 593 |
+
};
|
| 594 |
+
|
| 595 |
+
convert.ansi256.rgb = function (args) {
|
| 596 |
+
// Handle greyscale
|
| 597 |
+
if (args >= 232) {
|
| 598 |
+
const c = (args - 232) * 10 + 8;
|
| 599 |
+
return [c, c, c];
|
| 600 |
+
}
|
| 601 |
+
|
| 602 |
+
args -= 16;
|
| 603 |
+
|
| 604 |
+
let rem;
|
| 605 |
+
const r = Math.floor(args / 36) / 5 * 255;
|
| 606 |
+
const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
|
| 607 |
+
const b = (rem % 6) / 5 * 255;
|
| 608 |
+
|
| 609 |
+
return [r, g, b];
|
| 610 |
+
};
|
| 611 |
+
|
| 612 |
+
convert.rgb.hex = function (args) {
|
| 613 |
+
const integer = ((Math.round(args[0]) & 0xFF) << 16)
|
| 614 |
+
+ ((Math.round(args[1]) & 0xFF) << 8)
|
| 615 |
+
+ (Math.round(args[2]) & 0xFF);
|
| 616 |
+
|
| 617 |
+
const string = integer.toString(16).toUpperCase();
|
| 618 |
+
return '000000'.substring(string.length) + string;
|
| 619 |
+
};
|
| 620 |
+
|
| 621 |
+
convert.hex.rgb = function (args) {
|
| 622 |
+
const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
|
| 623 |
+
if (!match) {
|
| 624 |
+
return [0, 0, 0];
|
| 625 |
+
}
|
| 626 |
+
|
| 627 |
+
let colorString = match[0];
|
| 628 |
+
|
| 629 |
+
if (match[0].length === 3) {
|
| 630 |
+
colorString = colorString.split('').map(char => {
|
| 631 |
+
return char + char;
|
| 632 |
+
}).join('');
|
| 633 |
+
}
|
| 634 |
+
|
| 635 |
+
const integer = parseInt(colorString, 16);
|
| 636 |
+
const r = (integer >> 16) & 0xFF;
|
| 637 |
+
const g = (integer >> 8) & 0xFF;
|
| 638 |
+
const b = integer & 0xFF;
|
| 639 |
+
|
| 640 |
+
return [r, g, b];
|
| 641 |
+
};
|
| 642 |
+
|
| 643 |
+
convert.rgb.hcg = function (rgb) {
|
| 644 |
+
const r = rgb[0] / 255;
|
| 645 |
+
const g = rgb[1] / 255;
|
| 646 |
+
const b = rgb[2] / 255;
|
| 647 |
+
const max = Math.max(Math.max(r, g), b);
|
| 648 |
+
const min = Math.min(Math.min(r, g), b);
|
| 649 |
+
const chroma = (max - min);
|
| 650 |
+
let grayscale;
|
| 651 |
+
let hue;
|
| 652 |
+
|
| 653 |
+
if (chroma < 1) {
|
| 654 |
+
grayscale = min / (1 - chroma);
|
| 655 |
+
} else {
|
| 656 |
+
grayscale = 0;
|
| 657 |
+
}
|
| 658 |
+
|
| 659 |
+
if (chroma <= 0) {
|
| 660 |
+
hue = 0;
|
| 661 |
+
} else
|
| 662 |
+
if (max === r) {
|
| 663 |
+
hue = ((g - b) / chroma) % 6;
|
| 664 |
+
} else
|
| 665 |
+
if (max === g) {
|
| 666 |
+
hue = 2 + (b - r) / chroma;
|
| 667 |
+
} else {
|
| 668 |
+
hue = 4 + (r - g) / chroma;
|
| 669 |
+
}
|
| 670 |
+
|
| 671 |
+
hue /= 6;
|
| 672 |
+
hue %= 1;
|
| 673 |
+
|
| 674 |
+
return [hue * 360, chroma * 100, grayscale * 100];
|
| 675 |
+
};
|
| 676 |
+
|
| 677 |
+
convert.hsl.hcg = function (hsl) {
|
| 678 |
+
const s = hsl[1] / 100;
|
| 679 |
+
const l = hsl[2] / 100;
|
| 680 |
+
|
| 681 |
+
const c = l < 0.5 ? (2.0 * s * l) : (2.0 * s * (1.0 - l));
|
| 682 |
+
|
| 683 |
+
let f = 0;
|
| 684 |
+
if (c < 1.0) {
|
| 685 |
+
f = (l - 0.5 * c) / (1.0 - c);
|
| 686 |
+
}
|
| 687 |
+
|
| 688 |
+
return [hsl[0], c * 100, f * 100];
|
| 689 |
+
};
|
| 690 |
+
|
| 691 |
+
convert.hsv.hcg = function (hsv) {
|
| 692 |
+
const s = hsv[1] / 100;
|
| 693 |
+
const v = hsv[2] / 100;
|
| 694 |
+
|
| 695 |
+
const c = s * v;
|
| 696 |
+
let f = 0;
|
| 697 |
+
|
| 698 |
+
if (c < 1.0) {
|
| 699 |
+
f = (v - c) / (1 - c);
|
| 700 |
+
}
|
| 701 |
+
|
| 702 |
+
return [hsv[0], c * 100, f * 100];
|
| 703 |
+
};
|
| 704 |
+
|
| 705 |
+
convert.hcg.rgb = function (hcg) {
|
| 706 |
+
const h = hcg[0] / 360;
|
| 707 |
+
const c = hcg[1] / 100;
|
| 708 |
+
const g = hcg[2] / 100;
|
| 709 |
+
|
| 710 |
+
if (c === 0.0) {
|
| 711 |
+
return [g * 255, g * 255, g * 255];
|
| 712 |
+
}
|
| 713 |
+
|
| 714 |
+
const pure = [0, 0, 0];
|
| 715 |
+
const hi = (h % 1) * 6;
|
| 716 |
+
const v = hi % 1;
|
| 717 |
+
const w = 1 - v;
|
| 718 |
+
let mg = 0;
|
| 719 |
+
|
| 720 |
+
/* eslint-disable max-statements-per-line */
|
| 721 |
+
switch (Math.floor(hi)) {
|
| 722 |
+
case 0:
|
| 723 |
+
pure[0] = 1; pure[1] = v; pure[2] = 0; break;
|
| 724 |
+
case 1:
|
| 725 |
+
pure[0] = w; pure[1] = 1; pure[2] = 0; break;
|
| 726 |
+
case 2:
|
| 727 |
+
pure[0] = 0; pure[1] = 1; pure[2] = v; break;
|
| 728 |
+
case 3:
|
| 729 |
+
pure[0] = 0; pure[1] = w; pure[2] = 1; break;
|
| 730 |
+
case 4:
|
| 731 |
+
pure[0] = v; pure[1] = 0; pure[2] = 1; break;
|
| 732 |
+
default:
|
| 733 |
+
pure[0] = 1; pure[1] = 0; pure[2] = w;
|
| 734 |
+
}
|
| 735 |
+
/* eslint-enable max-statements-per-line */
|
| 736 |
+
|
| 737 |
+
mg = (1.0 - c) * g;
|
| 738 |
+
|
| 739 |
+
return [
|
| 740 |
+
(c * pure[0] + mg) * 255,
|
| 741 |
+
(c * pure[1] + mg) * 255,
|
| 742 |
+
(c * pure[2] + mg) * 255
|
| 743 |
+
];
|
| 744 |
+
};
|
| 745 |
+
|
| 746 |
+
convert.hcg.hsv = function (hcg) {
|
| 747 |
+
const c = hcg[1] / 100;
|
| 748 |
+
const g = hcg[2] / 100;
|
| 749 |
+
|
| 750 |
+
const v = c + g * (1.0 - c);
|
| 751 |
+
let f = 0;
|
| 752 |
+
|
| 753 |
+
if (v > 0.0) {
|
| 754 |
+
f = c / v;
|
| 755 |
+
}
|
| 756 |
+
|
| 757 |
+
return [hcg[0], f * 100, v * 100];
|
| 758 |
+
};
|
| 759 |
+
|
| 760 |
+
convert.hcg.hsl = function (hcg) {
|
| 761 |
+
const c = hcg[1] / 100;
|
| 762 |
+
const g = hcg[2] / 100;
|
| 763 |
+
|
| 764 |
+
const l = g * (1.0 - c) + 0.5 * c;
|
| 765 |
+
let s = 0;
|
| 766 |
+
|
| 767 |
+
if (l > 0.0 && l < 0.5) {
|
| 768 |
+
s = c / (2 * l);
|
| 769 |
+
} else
|
| 770 |
+
if (l >= 0.5 && l < 1.0) {
|
| 771 |
+
s = c / (2 * (1 - l));
|
| 772 |
+
}
|
| 773 |
+
|
| 774 |
+
return [hcg[0], s * 100, l * 100];
|
| 775 |
+
};
|
| 776 |
+
|
| 777 |
+
convert.hcg.hwb = function (hcg) {
|
| 778 |
+
const c = hcg[1] / 100;
|
| 779 |
+
const g = hcg[2] / 100;
|
| 780 |
+
const v = c + g * (1.0 - c);
|
| 781 |
+
return [hcg[0], (v - c) * 100, (1 - v) * 100];
|
| 782 |
+
};
|
| 783 |
+
|
| 784 |
+
convert.hwb.hcg = function (hwb) {
|
| 785 |
+
const w = hwb[1] / 100;
|
| 786 |
+
const b = hwb[2] / 100;
|
| 787 |
+
const v = 1 - b;
|
| 788 |
+
const c = v - w;
|
| 789 |
+
let g = 0;
|
| 790 |
+
|
| 791 |
+
if (c < 1) {
|
| 792 |
+
g = (v - c) / (1 - c);
|
| 793 |
+
}
|
| 794 |
+
|
| 795 |
+
return [hwb[0], c * 100, g * 100];
|
| 796 |
+
};
|
| 797 |
+
|
| 798 |
+
convert.apple.rgb = function (apple) {
|
| 799 |
+
return [(apple[0] / 65535) * 255, (apple[1] / 65535) * 255, (apple[2] / 65535) * 255];
|
| 800 |
+
};
|
| 801 |
+
|
| 802 |
+
convert.rgb.apple = function (rgb) {
|
| 803 |
+
return [(rgb[0] / 255) * 65535, (rgb[1] / 255) * 65535, (rgb[2] / 255) * 65535];
|
| 804 |
+
};
|
| 805 |
+
|
| 806 |
+
convert.gray.rgb = function (args) {
|
| 807 |
+
return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
|
| 808 |
+
};
|
| 809 |
+
|
| 810 |
+
convert.gray.hsl = function (args) {
|
| 811 |
+
return [0, 0, args[0]];
|
| 812 |
+
};
|
| 813 |
+
|
| 814 |
+
convert.gray.hsv = convert.gray.hsl;
|
| 815 |
+
|
| 816 |
+
convert.gray.hwb = function (gray) {
|
| 817 |
+
return [0, 100, gray[0]];
|
| 818 |
+
};
|
| 819 |
+
|
| 820 |
+
convert.gray.cmyk = function (gray) {
|
| 821 |
+
return [0, 0, 0, gray[0]];
|
| 822 |
+
};
|
| 823 |
+
|
| 824 |
+
convert.gray.lab = function (gray) {
|
| 825 |
+
return [gray[0], 0, 0];
|
| 826 |
+
};
|
| 827 |
+
|
| 828 |
+
convert.gray.hex = function (gray) {
|
| 829 |
+
const val = Math.round(gray[0] / 100 * 255) & 0xFF;
|
| 830 |
+
const integer = (val << 16) + (val << 8) + val;
|
| 831 |
+
|
| 832 |
+
const string = integer.toString(16).toUpperCase();
|
| 833 |
+
return '000000'.substring(string.length) + string;
|
| 834 |
+
};
|
| 835 |
+
|
| 836 |
+
convert.rgb.gray = function (rgb) {
|
| 837 |
+
const val = (rgb[0] + rgb[1] + rgb[2]) / 3;
|
| 838 |
+
return [val / 255 * 100];
|
| 839 |
+
};
|
node_modules/color-convert/index.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const conversions = require('./conversions');
|
| 2 |
+
const route = require('./route');
|
| 3 |
+
|
| 4 |
+
const convert = {};
|
| 5 |
+
|
| 6 |
+
const models = Object.keys(conversions);
|
| 7 |
+
|
| 8 |
+
function wrapRaw(fn) {
|
| 9 |
+
const wrappedFn = function (...args) {
|
| 10 |
+
const arg0 = args[0];
|
| 11 |
+
if (arg0 === undefined || arg0 === null) {
|
| 12 |
+
return arg0;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
if (arg0.length > 1) {
|
| 16 |
+
args = arg0;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
return fn(args);
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
// Preserve .conversion property if there is one
|
| 23 |
+
if ('conversion' in fn) {
|
| 24 |
+
wrappedFn.conversion = fn.conversion;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
return wrappedFn;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
function wrapRounded(fn) {
|
| 31 |
+
const wrappedFn = function (...args) {
|
| 32 |
+
const arg0 = args[0];
|
| 33 |
+
|
| 34 |
+
if (arg0 === undefined || arg0 === null) {
|
| 35 |
+
return arg0;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
if (arg0.length > 1) {
|
| 39 |
+
args = arg0;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
const result = fn(args);
|
| 43 |
+
|
| 44 |
+
// We're assuming the result is an array here.
|
| 45 |
+
// see notice in conversions.js; don't use box types
|
| 46 |
+
// in conversion functions.
|
| 47 |
+
if (typeof result === 'object') {
|
| 48 |
+
for (let len = result.length, i = 0; i < len; i++) {
|
| 49 |
+
result[i] = Math.round(result[i]);
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
return result;
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
// Preserve .conversion property if there is one
|
| 57 |
+
if ('conversion' in fn) {
|
| 58 |
+
wrappedFn.conversion = fn.conversion;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
return wrappedFn;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
models.forEach(fromModel => {
|
| 65 |
+
convert[fromModel] = {};
|
| 66 |
+
|
| 67 |
+
Object.defineProperty(convert[fromModel], 'channels', {value: conversions[fromModel].channels});
|
| 68 |
+
Object.defineProperty(convert[fromModel], 'labels', {value: conversions[fromModel].labels});
|
| 69 |
+
|
| 70 |
+
const routes = route(fromModel);
|
| 71 |
+
const routeModels = Object.keys(routes);
|
| 72 |
+
|
| 73 |
+
routeModels.forEach(toModel => {
|
| 74 |
+
const fn = routes[toModel];
|
| 75 |
+
|
| 76 |
+
convert[fromModel][toModel] = wrapRounded(fn);
|
| 77 |
+
convert[fromModel][toModel].raw = wrapRaw(fn);
|
| 78 |
+
});
|
| 79 |
+
});
|
| 80 |
+
|
| 81 |
+
module.exports = convert;
|
node_modules/color-convert/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "color-convert",
|
| 3 |
+
"description": "Plain color conversion functions",
|
| 4 |
+
"version": "2.0.1",
|
| 5 |
+
"author": "Heather Arthur <fayearthur@gmail.com>",
|
| 6 |
+
"license": "MIT",
|
| 7 |
+
"repository": "Qix-/color-convert",
|
| 8 |
+
"scripts": {
|
| 9 |
+
"pretest": "xo",
|
| 10 |
+
"test": "node test/basic.js"
|
| 11 |
+
},
|
| 12 |
+
"engines": {
|
| 13 |
+
"node": ">=7.0.0"
|
| 14 |
+
},
|
| 15 |
+
"keywords": [
|
| 16 |
+
"color",
|
| 17 |
+
"colour",
|
| 18 |
+
"convert",
|
| 19 |
+
"converter",
|
| 20 |
+
"conversion",
|
| 21 |
+
"rgb",
|
| 22 |
+
"hsl",
|
| 23 |
+
"hsv",
|
| 24 |
+
"hwb",
|
| 25 |
+
"cmyk",
|
| 26 |
+
"ansi",
|
| 27 |
+
"ansi16"
|
| 28 |
+
],
|
| 29 |
+
"files": [
|
| 30 |
+
"index.js",
|
| 31 |
+
"conversions.js",
|
| 32 |
+
"route.js"
|
| 33 |
+
],
|
| 34 |
+
"xo": {
|
| 35 |
+
"rules": {
|
| 36 |
+
"default-case": 0,
|
| 37 |
+
"no-inline-comments": 0,
|
| 38 |
+
"operator-linebreak": 0
|
| 39 |
+
}
|
| 40 |
+
},
|
| 41 |
+
"devDependencies": {
|
| 42 |
+
"chalk": "^2.4.2",
|
| 43 |
+
"xo": "^0.24.0"
|
| 44 |
+
},
|
| 45 |
+
"dependencies": {
|
| 46 |
+
"color-name": "~1.1.4"
|
| 47 |
+
}
|
| 48 |
+
}
|
node_modules/color-convert/route.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const conversions = require('./conversions');
|
| 2 |
+
|
| 3 |
+
/*
|
| 4 |
+
This function routes a model to all other models.
|
| 5 |
+
|
| 6 |
+
all functions that are routed have a property `.conversion` attached
|
| 7 |
+
to the returned synthetic function. This property is an array
|
| 8 |
+
of strings, each with the steps in between the 'from' and 'to'
|
| 9 |
+
color models (inclusive).
|
| 10 |
+
|
| 11 |
+
conversions that are not possible simply are not included.
|
| 12 |
+
*/
|
| 13 |
+
|
| 14 |
+
function buildGraph() {
|
| 15 |
+
const graph = {};
|
| 16 |
+
// https://jsperf.com/object-keys-vs-for-in-with-closure/3
|
| 17 |
+
const models = Object.keys(conversions);
|
| 18 |
+
|
| 19 |
+
for (let len = models.length, i = 0; i < len; i++) {
|
| 20 |
+
graph[models[i]] = {
|
| 21 |
+
// http://jsperf.com/1-vs-infinity
|
| 22 |
+
// micro-opt, but this is simple.
|
| 23 |
+
distance: -1,
|
| 24 |
+
parent: null
|
| 25 |
+
};
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
return graph;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
// https://en.wikipedia.org/wiki/Breadth-first_search
|
| 32 |
+
function deriveBFS(fromModel) {
|
| 33 |
+
const graph = buildGraph();
|
| 34 |
+
const queue = [fromModel]; // Unshift -> queue -> pop
|
| 35 |
+
|
| 36 |
+
graph[fromModel].distance = 0;
|
| 37 |
+
|
| 38 |
+
while (queue.length) {
|
| 39 |
+
const current = queue.pop();
|
| 40 |
+
const adjacents = Object.keys(conversions[current]);
|
| 41 |
+
|
| 42 |
+
for (let len = adjacents.length, i = 0; i < len; i++) {
|
| 43 |
+
const adjacent = adjacents[i];
|
| 44 |
+
const node = graph[adjacent];
|
| 45 |
+
|
| 46 |
+
if (node.distance === -1) {
|
| 47 |
+
node.distance = graph[current].distance + 1;
|
| 48 |
+
node.parent = current;
|
| 49 |
+
queue.unshift(adjacent);
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
return graph;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
function link(from, to) {
|
| 58 |
+
return function (args) {
|
| 59 |
+
return to(from(args));
|
| 60 |
+
};
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
function wrapConversion(toModel, graph) {
|
| 64 |
+
const path = [graph[toModel].parent, toModel];
|
| 65 |
+
let fn = conversions[graph[toModel].parent][toModel];
|
| 66 |
+
|
| 67 |
+
let cur = graph[toModel].parent;
|
| 68 |
+
while (graph[cur].parent) {
|
| 69 |
+
path.unshift(graph[cur].parent);
|
| 70 |
+
fn = link(conversions[graph[cur].parent][cur], fn);
|
| 71 |
+
cur = graph[cur].parent;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
fn.conversion = path;
|
| 75 |
+
return fn;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
module.exports = function (fromModel) {
|
| 79 |
+
const graph = deriveBFS(fromModel);
|
| 80 |
+
const conversion = {};
|
| 81 |
+
|
| 82 |
+
const models = Object.keys(graph);
|
| 83 |
+
for (let len = models.length, i = 0; i < len; i++) {
|
| 84 |
+
const toModel = models[i];
|
| 85 |
+
const node = graph[toModel];
|
| 86 |
+
|
| 87 |
+
if (node.parent === null) {
|
| 88 |
+
// No possible conversion, or this node is the source model.
|
| 89 |
+
continue;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
conversion[toModel] = wrapConversion(toModel, graph);
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
return conversion;
|
| 96 |
+
};
|
| 97 |
+
|
node_modules/combined-stream/License
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2011 Debuggable Limited <felix@debuggable.com>
|
| 2 |
+
|
| 3 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 5 |
+
in the Software without restriction, including without limitation the rights
|
| 6 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 7 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
The above copyright notice and this permission notice shall be included in
|
| 11 |
+
all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
AUTHORS OR COPYRIGHT HOLD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|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# combined-stream
|
| 2 |
+
|
| 3 |
+
A stream that emits multiple other streams one after another.
|
| 4 |
+
|
| 5 |
+
**NB** Currently `combined-stream` works with streams version 1 only. There is ongoing effort to switch this library to streams version 2. Any help is welcome. :) Meanwhile you can explore other libraries that provide streams2 support with more or less compatibility with `combined-stream`.
|
| 6 |
+
|
| 7 |
+
- [combined-stream2](https://www.npmjs.com/package/combined-stream2): A drop-in streams2-compatible replacement for the combined-stream module.
|
| 8 |
+
|
| 9 |
+
- [multistream](https://www.npmjs.com/package/multistream): A stream that emits multiple other streams one after another.
|
| 10 |
+
|
| 11 |
+
## Installation
|
| 12 |
+
|
| 13 |
+
``` bash
|
| 14 |
+
npm install combined-stream
|
| 15 |
+
```
|
| 16 |
+
|
| 17 |
+
## Usage
|
| 18 |
+
|
| 19 |
+
Here is a simple example that shows how you can use combined-stream to combine
|
| 20 |
+
two files into one:
|
| 21 |
+
|
| 22 |
+
``` javascript
|
| 23 |
+
var CombinedStream = require('combined-stream');
|
| 24 |
+
var fs = require('fs');
|
| 25 |
+
|
| 26 |
+
var combinedStream = CombinedStream.create();
|
| 27 |
+
combinedStream.append(fs.createReadStream('file1.txt'));
|
| 28 |
+
combinedStream.append(fs.createReadStream('file2.txt'));
|
| 29 |
+
|
| 30 |
+
combinedStream.pipe(fs.createWriteStream('combined.txt'));
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
While the example above works great, it will pause all source streams until
|
| 34 |
+
they are needed. If you don't want that to happen, you can set `pauseStreams`
|
| 35 |
+
to `false`:
|
| 36 |
+
|
| 37 |
+
``` javascript
|
| 38 |
+
var CombinedStream = require('combined-stream');
|
| 39 |
+
var fs = require('fs');
|
| 40 |
+
|
| 41 |
+
var combinedStream = CombinedStream.create({pauseStreams: false});
|
| 42 |
+
combinedStream.append(fs.createReadStream('file1.txt'));
|
| 43 |
+
combinedStream.append(fs.createReadStream('file2.txt'));
|
| 44 |
+
|
| 45 |
+
combinedStream.pipe(fs.createWriteStream('combined.txt'));
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
However, what if you don't have all the source streams yet, or you don't want
|
| 49 |
+
to allocate the resources (file descriptors, memory, etc.) for them right away?
|
| 50 |
+
Well, in that case you can simply provide a callback that supplies the stream
|
| 51 |
+
by calling a `next()` function:
|
| 52 |
+
|
| 53 |
+
``` javascript
|
| 54 |
+
var CombinedStream = require('combined-stream');
|
| 55 |
+
var fs = require('fs');
|
| 56 |
+
|
| 57 |
+
var combinedStream = CombinedStream.create();
|
| 58 |
+
combinedStream.append(function(next) {
|
| 59 |
+
next(fs.createReadStream('file1.txt'));
|
| 60 |
+
});
|
| 61 |
+
combinedStream.append(function(next) {
|
| 62 |
+
next(fs.createReadStream('file2.txt'));
|
| 63 |
+
});
|
| 64 |
+
|
| 65 |
+
combinedStream.pipe(fs.createWriteStream('combined.txt'));
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
## API
|
| 69 |
+
|
| 70 |
+
### CombinedStream.create([options])
|
| 71 |
+
|
| 72 |
+
Returns a new combined stream object. Available options are:
|
| 73 |
+
|
| 74 |
+
* `maxDataSize`
|
| 75 |
+
* `pauseStreams`
|
| 76 |
+
|
| 77 |
+
The effect of those options is described below.
|
| 78 |
+
|
| 79 |
+
### combinedStream.pauseStreams = `true`
|
| 80 |
+
|
| 81 |
+
Whether to apply back pressure to the underlaying streams. If set to `false`,
|
| 82 |
+
the underlaying streams will never be paused. If set to `true`, the
|
| 83 |
+
underlaying streams will be paused right after being appended, as well as when
|
| 84 |
+
`delayedStream.pipe()` wants to throttle.
|
| 85 |
+
|
| 86 |
+
### combinedStream.maxDataSize = `2 * 1024 * 1024`
|
| 87 |
+
|
| 88 |
+
The maximum amount of bytes (or characters) to buffer for all source streams.
|
| 89 |
+
If this value is exceeded, `combinedStream` emits an `'error'` event.
|
| 90 |
+
|
| 91 |
+
### combinedStream.dataSize = `0`
|
| 92 |
+
|
| 93 |
+
The amount of bytes (or characters) currently buffered by `combinedStream`.
|
| 94 |
+
|
| 95 |
+
### combinedStream.append(stream)
|
| 96 |
+
|
| 97 |
+
Appends the given `stream` to the combinedStream object. If `pauseStreams` is
|
| 98 |
+
set to `true, this stream will also be paused right away.
|
| 99 |
+
|
| 100 |
+
`streams` can also be a function that takes one parameter called `next`. `next`
|
| 101 |
+
is a function that must be invoked in order to provide the `next` stream, see
|
| 102 |
+
example above.
|
| 103 |
+
|
| 104 |
+
Regardless of how the `stream` is appended, combined-stream always attaches an
|
| 105 |
+
`'error'` listener to it, so you don't have to do that manually.
|
| 106 |
+
|
| 107 |
+
Special case: `stream` can also be a String or Buffer.
|
| 108 |
+
|
| 109 |
+
### combinedStream.write(data)
|
| 110 |
+
|
| 111 |
+
You should not call this, `combinedStream` takes care of piping the appended
|
| 112 |
+
streams into itself for you.
|
| 113 |
+
|
| 114 |
+
### combinedStream.resume()
|
| 115 |
+
|
| 116 |
+
Causes `combinedStream` to start drain the streams it manages. The function is
|
| 117 |
+
idempotent, and also emits a `'resume'` event each time which usually goes to
|
| 118 |
+
the stream that is currently being drained.
|
| 119 |
+
|
| 120 |
+
### combinedStream.pause();
|
| 121 |
+
|
| 122 |
+
If `combinedStream.pauseStreams` is set to `false`, this does nothing.
|
| 123 |
+
Otherwise a `'pause'` event is emitted, this goes to the stream that is
|
| 124 |
+
currently being drained, so you can use it to apply back pressure.
|
| 125 |
+
|
| 126 |
+
### combinedStream.end();
|
| 127 |
+
|
| 128 |
+
Sets `combinedStream.writable` to false, emits an `'end'` event, and removes
|
| 129 |
+
all streams from the queue.
|
| 130 |
+
|
| 131 |
+
### combinedStream.destroy();
|
| 132 |
+
|
| 133 |
+
Same as `combinedStream.end()`, except it emits a `'close'` event instead of
|
| 134 |
+
`'end'`.
|
| 135 |
+
|
| 136 |
+
## License
|
| 137 |
+
|
| 138 |
+
combined-stream is licensed under the MIT license.
|
node_modules/combined-stream/lib/combined_stream.js
ADDED
|
@@ -0,0 +1,208 @@
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
var util = require('util');
|
| 2 |
+
var Stream = require('stream').Stream;
|
| 3 |
+
var DelayedStream = require('delayed-stream');
|
| 4 |
+
|
| 5 |
+
module.exports = CombinedStream;
|
| 6 |
+
function CombinedStream() {
|
| 7 |
+
this.writable = false;
|
| 8 |
+
this.readable = true;
|
| 9 |
+
this.dataSize = 0;
|
| 10 |
+
this.maxDataSize = 2 * 1024 * 1024;
|
| 11 |
+
this.pauseStreams = true;
|
| 12 |
+
|
| 13 |
+
this._released = false;
|
| 14 |
+
this._streams = [];
|
| 15 |
+
this._currentStream = null;
|
| 16 |
+
this._insideLoop = false;
|
| 17 |
+
this._pendingNext = false;
|
| 18 |
+
}
|
| 19 |
+
util.inherits(CombinedStream, Stream);
|
| 20 |
+
|
| 21 |
+
CombinedStream.create = function(options) {
|
| 22 |
+
var combinedStream = new this();
|
| 23 |
+
|
| 24 |
+
options = options || {};
|
| 25 |
+
for (var option in options) {
|
| 26 |
+
combinedStream[option] = options[option];
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
return combinedStream;
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
CombinedStream.isStreamLike = function(stream) {
|
| 33 |
+
return (typeof stream !== 'function')
|
| 34 |
+
&& (typeof stream !== 'string')
|
| 35 |
+
&& (typeof stream !== 'boolean')
|
| 36 |
+
&& (typeof stream !== 'number')
|
| 37 |
+
&& (!Buffer.isBuffer(stream));
|
| 38 |
+
};
|
| 39 |
+
|
| 40 |
+
CombinedStream.prototype.append = function(stream) {
|
| 41 |
+
var isStreamLike = CombinedStream.isStreamLike(stream);
|
| 42 |
+
|
| 43 |
+
if (isStreamLike) {
|
| 44 |
+
if (!(stream instanceof DelayedStream)) {
|
| 45 |
+
var newStream = DelayedStream.create(stream, {
|
| 46 |
+
maxDataSize: Infinity,
|
| 47 |
+
pauseStream: this.pauseStreams,
|
| 48 |
+
});
|
| 49 |
+
stream.on('data', this._checkDataSize.bind(this));
|
| 50 |
+
stream = newStream;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
this._handleErrors(stream);
|
| 54 |
+
|
| 55 |
+
if (this.pauseStreams) {
|
| 56 |
+
stream.pause();
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
this._streams.push(stream);
|
| 61 |
+
return this;
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
CombinedStream.prototype.pipe = function(dest, options) {
|
| 65 |
+
Stream.prototype.pipe.call(this, dest, options);
|
| 66 |
+
this.resume();
|
| 67 |
+
return dest;
|
| 68 |
+
};
|
| 69 |
+
|
| 70 |
+
CombinedStream.prototype._getNext = function() {
|
| 71 |
+
this._currentStream = null;
|
| 72 |
+
|
| 73 |
+
if (this._insideLoop) {
|
| 74 |
+
this._pendingNext = true;
|
| 75 |
+
return; // defer call
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
this._insideLoop = true;
|
| 79 |
+
try {
|
| 80 |
+
do {
|
| 81 |
+
this._pendingNext = false;
|
| 82 |
+
this._realGetNext();
|
| 83 |
+
} while (this._pendingNext);
|
| 84 |
+
} finally {
|
| 85 |
+
this._insideLoop = false;
|
| 86 |
+
}
|
| 87 |
+
};
|
| 88 |
+
|
| 89 |
+
CombinedStream.prototype._realGetNext = function() {
|
| 90 |
+
var stream = this._streams.shift();
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
if (typeof stream == 'undefined') {
|
| 94 |
+
this.end();
|
| 95 |
+
return;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
if (typeof stream !== 'function') {
|
| 99 |
+
this._pipeNext(stream);
|
| 100 |
+
return;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
var getStream = stream;
|
| 104 |
+
getStream(function(stream) {
|
| 105 |
+
var isStreamLike = CombinedStream.isStreamLike(stream);
|
| 106 |
+
if (isStreamLike) {
|
| 107 |
+
stream.on('data', this._checkDataSize.bind(this));
|
| 108 |
+
this._handleErrors(stream);
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
this._pipeNext(stream);
|
| 112 |
+
}.bind(this));
|
| 113 |
+
};
|
| 114 |
+
|
| 115 |
+
CombinedStream.prototype._pipeNext = function(stream) {
|
| 116 |
+
this._currentStream = stream;
|
| 117 |
+
|
| 118 |
+
var isStreamLike = CombinedStream.isStreamLike(stream);
|
| 119 |
+
if (isStreamLike) {
|
| 120 |
+
stream.on('end', this._getNext.bind(this));
|
| 121 |
+
stream.pipe(this, {end: false});
|
| 122 |
+
return;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
var value = stream;
|
| 126 |
+
this.write(value);
|
| 127 |
+
this._getNext();
|
| 128 |
+
};
|
| 129 |
+
|
| 130 |
+
CombinedStream.prototype._handleErrors = function(stream) {
|
| 131 |
+
var self = this;
|
| 132 |
+
stream.on('error', function(err) {
|
| 133 |
+
self._emitError(err);
|
| 134 |
+
});
|
| 135 |
+
};
|
| 136 |
+
|
| 137 |
+
CombinedStream.prototype.write = function(data) {
|
| 138 |
+
this.emit('data', data);
|
| 139 |
+
};
|
| 140 |
+
|
| 141 |
+
CombinedStream.prototype.pause = function() {
|
| 142 |
+
if (!this.pauseStreams) {
|
| 143 |
+
return;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
if(this.pauseStreams && this._currentStream && typeof(this._currentStream.pause) == 'function') this._currentStream.pause();
|
| 147 |
+
this.emit('pause');
|
| 148 |
+
};
|
| 149 |
+
|
| 150 |
+
CombinedStream.prototype.resume = function() {
|
| 151 |
+
if (!this._released) {
|
| 152 |
+
this._released = true;
|
| 153 |
+
this.writable = true;
|
| 154 |
+
this._getNext();
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
if(this.pauseStreams && this._currentStream && typeof(this._currentStream.resume) == 'function') this._currentStream.resume();
|
| 158 |
+
this.emit('resume');
|
| 159 |
+
};
|
| 160 |
+
|
| 161 |
+
CombinedStream.prototype.end = function() {
|
| 162 |
+
this._reset();
|
| 163 |
+
this.emit('end');
|
| 164 |
+
};
|
| 165 |
+
|
| 166 |
+
CombinedStream.prototype.destroy = function() {
|
| 167 |
+
this._reset();
|
| 168 |
+
this.emit('close');
|
| 169 |
+
};
|
| 170 |
+
|
| 171 |
+
CombinedStream.prototype._reset = function() {
|
| 172 |
+
this.writable = false;
|
| 173 |
+
this._streams = [];
|
| 174 |
+
this._currentStream = null;
|
| 175 |
+
};
|
| 176 |
+
|
| 177 |
+
CombinedStream.prototype._checkDataSize = function() {
|
| 178 |
+
this._updateDataSize();
|
| 179 |
+
if (this.dataSize <= this.maxDataSize) {
|
| 180 |
+
return;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
var message =
|
| 184 |
+
'DelayedStream#maxDataSize of ' + this.maxDataSize + ' bytes exceeded.';
|
| 185 |
+
this._emitError(new Error(message));
|
| 186 |
+
};
|
| 187 |
+
|
| 188 |
+
CombinedStream.prototype._updateDataSize = function() {
|
| 189 |
+
this.dataSize = 0;
|
| 190 |
+
|
| 191 |
+
var self = this;
|
| 192 |
+
this._streams.forEach(function(stream) {
|
| 193 |
+
if (!stream.dataSize) {
|
| 194 |
+
return;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
self.dataSize += stream.dataSize;
|
| 198 |
+
});
|
| 199 |
+
|
| 200 |
+
if (this._currentStream && this._currentStream.dataSize) {
|
| 201 |
+
this.dataSize += this._currentStream.dataSize;
|
| 202 |
+
}
|
| 203 |
+
};
|
| 204 |
+
|
| 205 |
+
CombinedStream.prototype._emitError = function(err) {
|
| 206 |
+
this._reset();
|
| 207 |
+
this.emit('error', err);
|
| 208 |
+
};
|
node_modules/combined-stream/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"author": "Felix Geisendörfer <felix@debuggable.com> (http://debuggable.com/)",
|
| 3 |
+
"name": "combined-stream",
|
| 4 |
+
"description": "A stream that emits multiple other streams one after another.",
|
| 5 |
+
"version": "1.0.8",
|
| 6 |
+
"homepage": "https://github.com/felixge/node-combined-stream",
|
| 7 |
+
"repository": {
|
| 8 |
+
"type": "git",
|
| 9 |
+
"url": "git://github.com/felixge/node-combined-stream.git"
|
| 10 |
+
},
|
| 11 |
+
"main": "./lib/combined_stream",
|
| 12 |
+
"scripts": {
|
| 13 |
+
"test": "node test/run.js"
|
| 14 |
+
},
|
| 15 |
+
"engines": {
|
| 16 |
+
"node": ">= 0.8"
|
| 17 |
+
},
|
| 18 |
+
"dependencies": {
|
| 19 |
+
"delayed-stream": "~1.0.0"
|
| 20 |
+
},
|
| 21 |
+
"devDependencies": {
|
| 22 |
+
"far": "~0.0.7"
|
| 23 |
+
},
|
| 24 |
+
"license": "MIT"
|
| 25 |
+
}
|
node_modules/combined-stream/yarn.lock
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
| 2 |
+
# yarn lockfile v1
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
delayed-stream@~1.0.0:
|
| 6 |
+
version "1.0.0"
|
| 7 |
+
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
|
| 8 |
+
|
| 9 |
+
far@~0.0.7:
|
| 10 |
+
version "0.0.7"
|
| 11 |
+
resolved "https://registry.yarnpkg.com/far/-/far-0.0.7.tgz#01c1fd362bcd26ce9cf161af3938aa34619f79a7"
|
| 12 |
+
dependencies:
|
| 13 |
+
oop "0.0.3"
|
| 14 |
+
|
| 15 |
+
oop@0.0.3:
|
| 16 |
+
version "0.0.3"
|
| 17 |
+
resolved "https://registry.yarnpkg.com/oop/-/oop-0.0.3.tgz#70fa405a5650891a194fdc82ca68dad6dabf4401"
|
node_modules/component-emitter/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
(The MIT License)
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2014 Component contributors <dev@component.io>
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person
|
| 6 |
+
obtaining a copy of this software and associated documentation
|
| 7 |
+
files (the "Software"), to deal in the Software without
|
| 8 |
+
restriction, including without limitation the rights to use,
|
| 9 |
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 10 |
+
copies of the Software, and to permit persons to whom the
|
| 11 |
+
Software is furnished to do so, subject to the following
|
| 12 |
+
conditions:
|
| 13 |
+
|
| 14 |
+
The above copyright notice and this permission notice shall be
|
| 15 |
+
included in all copies or substantial portions of the Software.
|
| 16 |
+
|
| 17 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 18 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
| 19 |
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 20 |
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
| 21 |
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
| 22 |
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 23 |
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
| 24 |
+
OTHER DEALINGS IN THE SOFTWARE.
|
node_modules/component-emitter/Readme.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Emitter [](https://travis-ci.org/component/emitter)
|
| 2 |
+
|
| 3 |
+
Event emitter component.
|
| 4 |
+
|
| 5 |
+
## Installation
|
| 6 |
+
|
| 7 |
+
```
|
| 8 |
+
$ component install component/emitter
|
| 9 |
+
```
|
| 10 |
+
|
| 11 |
+
## API
|
| 12 |
+
|
| 13 |
+
### Emitter(obj)
|
| 14 |
+
|
| 15 |
+
The `Emitter` may also be used as a mixin. For example
|
| 16 |
+
a "plain" object may become an emitter, or you may
|
| 17 |
+
extend an existing prototype.
|
| 18 |
+
|
| 19 |
+
As an `Emitter` instance:
|
| 20 |
+
|
| 21 |
+
```js
|
| 22 |
+
var Emitter = require('emitter');
|
| 23 |
+
var emitter = new Emitter;
|
| 24 |
+
emitter.emit('something');
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
As a mixin:
|
| 28 |
+
|
| 29 |
+
```js
|
| 30 |
+
var Emitter = require('emitter');
|
| 31 |
+
var user = { name: 'tobi' };
|
| 32 |
+
Emitter(user);
|
| 33 |
+
|
| 34 |
+
user.emit('im a user');
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
As a prototype mixin:
|
| 38 |
+
|
| 39 |
+
```js
|
| 40 |
+
var Emitter = require('emitter');
|
| 41 |
+
Emitter(User.prototype);
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
### Emitter#on(event, fn)
|
| 45 |
+
|
| 46 |
+
Register an `event` handler `fn`.
|
| 47 |
+
|
| 48 |
+
### Emitter#once(event, fn)
|
| 49 |
+
|
| 50 |
+
Register a single-shot `event` handler `fn`,
|
| 51 |
+
removed immediately after it is invoked the
|
| 52 |
+
first time.
|
| 53 |
+
|
| 54 |
+
### Emitter#off(event, fn)
|
| 55 |
+
|
| 56 |
+
* Pass `event` and `fn` to remove a listener.
|
| 57 |
+
* Pass `event` to remove all listeners on that event.
|
| 58 |
+
* Pass nothing to remove all listeners on all events.
|
| 59 |
+
|
| 60 |
+
### Emitter#emit(event, ...)
|
| 61 |
+
|
| 62 |
+
Emit an `event` with variable option args.
|
| 63 |
+
|
| 64 |
+
### Emitter#listeners(event)
|
| 65 |
+
|
| 66 |
+
Return an array of callbacks, or an empty array.
|
| 67 |
+
|
| 68 |
+
### Emitter#hasListeners(event)
|
| 69 |
+
|
| 70 |
+
Check if this emitter has `event` handlers.
|
| 71 |
+
|
| 72 |
+
## License
|
| 73 |
+
|
| 74 |
+
MIT
|
node_modules/component-emitter/index.js
ADDED
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
/**
|
| 3 |
+
* Expose `Emitter`.
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
if (typeof module !== 'undefined') {
|
| 7 |
+
module.exports = Emitter;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
* Initialize a new `Emitter`.
|
| 12 |
+
*
|
| 13 |
+
* @api public
|
| 14 |
+
*/
|
| 15 |
+
|
| 16 |
+
function Emitter(obj) {
|
| 17 |
+
if (obj) return mixin(obj);
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
/**
|
| 21 |
+
* Mixin the emitter properties.
|
| 22 |
+
*
|
| 23 |
+
* @param {Object} obj
|
| 24 |
+
* @return {Object}
|
| 25 |
+
* @api private
|
| 26 |
+
*/
|
| 27 |
+
|
| 28 |
+
function mixin(obj) {
|
| 29 |
+
for (var key in Emitter.prototype) {
|
| 30 |
+
obj[key] = Emitter.prototype[key];
|
| 31 |
+
}
|
| 32 |
+
return obj;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* Listen on the given `event` with `fn`.
|
| 37 |
+
*
|
| 38 |
+
* @param {String} event
|
| 39 |
+
* @param {Function} fn
|
| 40 |
+
* @return {Emitter}
|
| 41 |
+
* @api public
|
| 42 |
+
*/
|
| 43 |
+
|
| 44 |
+
Emitter.prototype.on =
|
| 45 |
+
Emitter.prototype.addEventListener = function(event, fn){
|
| 46 |
+
this._callbacks = this._callbacks || {};
|
| 47 |
+
(this._callbacks['$' + event] = this._callbacks['$' + event] || [])
|
| 48 |
+
.push(fn);
|
| 49 |
+
return this;
|
| 50 |
+
};
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* Adds an `event` listener that will be invoked a single
|
| 54 |
+
* time then automatically removed.
|
| 55 |
+
*
|
| 56 |
+
* @param {String} event
|
| 57 |
+
* @param {Function} fn
|
| 58 |
+
* @return {Emitter}
|
| 59 |
+
* @api public
|
| 60 |
+
*/
|
| 61 |
+
|
| 62 |
+
Emitter.prototype.once = function(event, fn){
|
| 63 |
+
function on() {
|
| 64 |
+
this.off(event, on);
|
| 65 |
+
fn.apply(this, arguments);
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
on.fn = fn;
|
| 69 |
+
this.on(event, on);
|
| 70 |
+
return this;
|
| 71 |
+
};
|
| 72 |
+
|
| 73 |
+
/**
|
| 74 |
+
* Remove the given callback for `event` or all
|
| 75 |
+
* registered callbacks.
|
| 76 |
+
*
|
| 77 |
+
* @param {String} event
|
| 78 |
+
* @param {Function} fn
|
| 79 |
+
* @return {Emitter}
|
| 80 |
+
* @api public
|
| 81 |
+
*/
|
| 82 |
+
|
| 83 |
+
Emitter.prototype.off =
|
| 84 |
+
Emitter.prototype.removeListener =
|
| 85 |
+
Emitter.prototype.removeAllListeners =
|
| 86 |
+
Emitter.prototype.removeEventListener = function(event, fn){
|
| 87 |
+
this._callbacks = this._callbacks || {};
|
| 88 |
+
|
| 89 |
+
// all
|
| 90 |
+
if (0 == arguments.length) {
|
| 91 |
+
this._callbacks = {};
|
| 92 |
+
return this;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
// specific event
|
| 96 |
+
var callbacks = this._callbacks['$' + event];
|
| 97 |
+
if (!callbacks) return this;
|
| 98 |
+
|
| 99 |
+
// remove all handlers
|
| 100 |
+
if (1 == arguments.length) {
|
| 101 |
+
delete this._callbacks['$' + event];
|
| 102 |
+
return this;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
// remove specific handler
|
| 106 |
+
var cb;
|
| 107 |
+
for (var i = 0; i < callbacks.length; i++) {
|
| 108 |
+
cb = callbacks[i];
|
| 109 |
+
if (cb === fn || cb.fn === fn) {
|
| 110 |
+
callbacks.splice(i, 1);
|
| 111 |
+
break;
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
// Remove event specific arrays for event types that no
|
| 116 |
+
// one is subscribed for to avoid memory leak.
|
| 117 |
+
if (callbacks.length === 0) {
|
| 118 |
+
delete this._callbacks['$' + event];
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
return this;
|
| 122 |
+
};
|
| 123 |
+
|
| 124 |
+
/**
|
| 125 |
+
* Emit `event` with the given args.
|
| 126 |
+
*
|
| 127 |
+
* @param {String} event
|
| 128 |
+
* @param {Mixed} ...
|
| 129 |
+
* @return {Emitter}
|
| 130 |
+
*/
|
| 131 |
+
|
| 132 |
+
Emitter.prototype.emit = function(event){
|
| 133 |
+
this._callbacks = this._callbacks || {};
|
| 134 |
+
|
| 135 |
+
var args = new Array(arguments.length - 1)
|
| 136 |
+
, callbacks = this._callbacks['$' + event];
|
| 137 |
+
|
| 138 |
+
for (var i = 1; i < arguments.length; i++) {
|
| 139 |
+
args[i - 1] = arguments[i];
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
if (callbacks) {
|
| 143 |
+
callbacks = callbacks.slice(0);
|
| 144 |
+
for (var i = 0, len = callbacks.length; i < len; ++i) {
|
| 145 |
+
callbacks[i].apply(this, args);
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
return this;
|
| 150 |
+
};
|
| 151 |
+
|
| 152 |
+
/**
|
| 153 |
+
* Return array of callbacks for `event`.
|
| 154 |
+
*
|
| 155 |
+
* @param {String} event
|
| 156 |
+
* @return {Array}
|
| 157 |
+
* @api public
|
| 158 |
+
*/
|
| 159 |
+
|
| 160 |
+
Emitter.prototype.listeners = function(event){
|
| 161 |
+
this._callbacks = this._callbacks || {};
|
| 162 |
+
return this._callbacks['$' + event] || [];
|
| 163 |
+
};
|
| 164 |
+
|
| 165 |
+
/**
|
| 166 |
+
* Check if this emitter has `event` handlers.
|
| 167 |
+
*
|
| 168 |
+
* @param {String} event
|
| 169 |
+
* @return {Boolean}
|
| 170 |
+
* @api public
|
| 171 |
+
*/
|
| 172 |
+
|
| 173 |
+
Emitter.prototype.hasListeners = function(event){
|
| 174 |
+
return !! this.listeners(event).length;
|
| 175 |
+
};
|
node_modules/component-emitter/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "component-emitter",
|
| 3 |
+
"description": "Event emitter",
|
| 4 |
+
"version": "1.3.1",
|
| 5 |
+
"license": "MIT",
|
| 6 |
+
"funding": "https://github.com/sponsors/sindresorhus",
|
| 7 |
+
"devDependencies": {
|
| 8 |
+
"mocha": "*",
|
| 9 |
+
"should": "*"
|
| 10 |
+
},
|
| 11 |
+
"component": {
|
| 12 |
+
"scripts": {
|
| 13 |
+
"emitter/index.js": "index.js"
|
| 14 |
+
}
|
| 15 |
+
},
|
| 16 |
+
"main": "index.js",
|
| 17 |
+
"repository": {
|
| 18 |
+
"type": "git",
|
| 19 |
+
"url": "https://github.com/sindresorhus/component-emitter.git"
|
| 20 |
+
},
|
| 21 |
+
"scripts": {
|
| 22 |
+
"test": "make test"
|
| 23 |
+
},
|
| 24 |
+
"files": [
|
| 25 |
+
"index.js",
|
| 26 |
+
"LICENSE"
|
| 27 |
+
]
|
| 28 |
+
}
|
node_modules/compress-commons/CHANGELOG.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Changelog
|
| 2 |
+
|
| 3 |
+
**5.0.2** — <small>_February 26, 2024_</small> — [Diff](https://github.com/archiverjs/node-compress-commons/compare/5.0.1...5.0.2)
|
| 4 |
+
|
| 5 |
+
**5.0.1** — <small>_September 3, 2023_</small> — [Diff](https://github.com/archiverjs/node-compress-commons/compare/5.0.0...5.0.1)
|
| 6 |
+
|
| 7 |
+
**5.0.0** — <small>_September 2, 2023_</small> — [Diff](https://github.com/archiverjs/node-compress-commons/compare/4.1.2...5.0.0)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
**4.1.2** — <small>_September 2, 2023_</small> — [Diff](https://github.com/archiverjs/node-compress-commons/compare/4.1.1...4.1.2)
|
| 11 |
+
|
| 12 |
+
**4.1.1** — <small>_May 30th, 2021_</small> — [Diff](https://github.com/archiverjs/node-compress-commons/compare/4.1.0...4.1.1)
|
| 13 |
+
|
| 14 |
+
### Maintenance
|
| 15 |
+
- Bump mocha from 8.2.1 to 8.4.0 (#70)
|
| 16 |
+
- Bump crc32-stream from 4.0.1 to 4.0.2 (#59)
|
| 17 |
+
- Bump y18n from 4.0.0 to 4.0.1 (#69)
|
| 18 |
+
- Bump chai from 4.2.0 to 4.3.4 (#67)
|
| 19 |
+
- Bump actions/setup-node from 2.1.4 to 2.1.5 (#71)
|
| 20 |
+
|
| 21 |
+
**4.1.0** — <small>_March 2, 2021_</small> — [Diff](https://github.com/archiverjs/node-compress-commons/compare/4.0.1...4.1.0)
|
| 22 |
+
|
| 23 |
+
### Features
|
| 24 |
+
|
| 25 |
+
- Allow prepending forward slash in entry name (#63)
|
| 26 |
+
|
| 27 |
+
### Maintenance
|
| 28 |
+
|
| 29 |
+
- Bump actions/setup-node from v2.1.2 to v2.1.4 (#58)
|
| 30 |
+
|
| 31 |
+
**4.0.1** — <small>_July 20, 2020_</small> — [Diff](https://github.com/archiverjs/node-compress-commons/compare/4.0.0...4.0.1)
|
| 32 |
+
|
| 33 |
+
* Bump crc32-stream from 3.0.1 to 4.0.0 (#43) @dependabot
|
| 34 |
+
|
| 35 |
+
**4.0.0** — <small>_July 18, 2020_</small> — [Diff](https://github.com/archiverjs/node-compress-commons/compare/3.0.0...4.0.0)
|
| 36 |
+
|
| 37 |
+
* Bump mocha from 5.2.0 to 8.0.1 (#36) @dependabot
|
| 38 |
+
* Bump readable-stream from 2.3.7 to 3.6.0 (#39) @dependabot
|
| 39 |
+
* Bump actions/setup-node from v1 to v2.1.0 (#41) @dependabot
|
| 40 |
+
* Bump rimraf from 2.7.1 to 3.0.2 (#38) @dependabot
|
| 41 |
+
* Bump mkdirp from 0.5.5 to 1.0.4 (#37) @dependabot
|
| 42 |
+
* Bump actions/checkout from v1 to v2.3.1 (#40) @dependabot
|
| 43 |
+
* remove support for node < 10 (#42) @ctalkington
|
| 44 |
+
|
| 45 |
+
**3.0.0** — <small>_April 14, 2020_</small> — [Diff](https://github.com/archiverjs/node-compress-commons/compare/2.1.1...3.0.0)
|
| 46 |
+
|
| 47 |
+
- breaking: slowly catch up with node LTS, remove support for versions under 8.
|
| 48 |
+
- update multiple deps.
|
| 49 |
+
|
| 50 |
+
**2.1.1** — <small>_August 2, 2019_</small> — [Diff](https://github.com/archiverjs/node-compress-commons/compare/2.1.0...2.1.1)
|
| 51 |
+
|
| 52 |
+
- update crc32-stream to v3.0.1
|
| 53 |
+
|
| 54 |
+
**2.1.0** — <small>_August 2, 2019_</small> — [Diff](https://github.com/archiverjs/node-compress-commons/compare/2.0.0...2.1.0)
|
| 55 |
+
|
| 56 |
+
- update crc32-stream to v3.0.0
|
| 57 |
+
|
| 58 |
+
**2.0.0** — <small>_July 19, 2019_</small> — [Diff](https://github.com/archiverjs/node-compress-commons/compare/1.2.2...2.0.0)
|
| 59 |
+
|
| 60 |
+
- breaking: follow node LTS, remove support for versions under 6.
|
| 61 |
+
- test: now targeting node v10 and v12
|
| 62 |
+
- fix: update Buffer calls to alloc/from
|
| 63 |
+
- fix: Add offset to buffer call (#31)
|
| 64 |
+
- other: update normalize-path@3 (#34)
|
| 65 |
+
- other: update dependencies
|
| 66 |
+
|
| 67 |
+
[Release Archive](https://github.com/archiverjs/node-compress-commons/releases)
|
node_modules/compress-commons/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2014 Chris Talkington, contributors.
|
| 2 |
+
|
| 3 |
+
Permission is hereby granted, free of charge, to any person
|
| 4 |
+
obtaining a copy of this software and associated documentation
|
| 5 |
+
files (the "Software"), to deal in the Software without
|
| 6 |
+
restriction, including without limitation the rights to use,
|
| 7 |
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
copies of the Software, and to permit persons to whom the
|
| 9 |
+
Software is furnished to do so, subject to the following
|
| 10 |
+
conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be
|
| 13 |
+
included in all copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 16 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
| 17 |
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 18 |
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
| 19 |
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
| 20 |
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 21 |
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
| 22 |
+
OTHER DEALINGS IN THE SOFTWARE.
|
node_modules/compress-commons/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Compress Commons
|
| 2 |
+
|
| 3 |
+
Compress Commons is a library that defines a common interface for working with archive formats within node.
|
| 4 |
+
|
| 5 |
+
[](https://nodei.co/npm/compress-commons/)
|
| 6 |
+
|
| 7 |
+
## Install
|
| 8 |
+
|
| 9 |
+
```bash
|
| 10 |
+
npm install compress-commons --save
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
You can also use `npm install https://github.com/archiverjs/node-compress-commons/archive/master.tar.gz` to test upcoming versions.
|
| 14 |
+
|
| 15 |
+
## Things of Interest
|
| 16 |
+
|
| 17 |
+
- [Changelog](https://github.com/archiverjs/node-compress-commons/releases)
|
| 18 |
+
- [Contributing](https://github.com/archiverjs/node-compress-commons/blob/master/CONTRIBUTING.md)
|
| 19 |
+
- [MIT License](https://github.com/archiverjs/node-compress-commons/blob/master/LICENSE-MIT)
|
| 20 |
+
|
| 21 |
+
## Credits
|
| 22 |
+
|
| 23 |
+
Concept inspired by [Apache Commons Compress](http://commons.apache.org/proper/commons-compress/)™.
|
| 24 |
+
|
| 25 |
+
Some logic derived from [Apache Commons Compress](http://commons.apache.org/proper/commons-compress/)™ and [OpenJDK 7](http://openjdk.java.net/).
|
node_modules/compress-commons/lib/archivers/archive-entry.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* node-compress-commons
|
| 3 |
+
*
|
| 4 |
+
* Copyright (c) 2014 Chris Talkington, contributors.
|
| 5 |
+
* Licensed under the MIT license.
|
| 6 |
+
* https://github.com/archiverjs/node-compress-commons/blob/master/LICENSE-MIT
|
| 7 |
+
*/
|
| 8 |
+
var ArchiveEntry = module.exports = function() {};
|
| 9 |
+
|
| 10 |
+
ArchiveEntry.prototype.getName = function() {};
|
| 11 |
+
|
| 12 |
+
ArchiveEntry.prototype.getSize = function() {};
|
| 13 |
+
|
| 14 |
+
ArchiveEntry.prototype.getLastModifiedDate = function() {};
|
| 15 |
+
|
| 16 |
+
ArchiveEntry.prototype.isDirectory = function() {};
|
node_modules/compress-commons/lib/archivers/archive-output-stream.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* node-compress-commons
|
| 3 |
+
*
|
| 4 |
+
* Copyright (c) 2014 Chris Talkington, contributors.
|
| 5 |
+
* Licensed under the MIT license.
|
| 6 |
+
* https://github.com/archiverjs/node-compress-commons/blob/master/LICENSE-MIT
|
| 7 |
+
*/
|
| 8 |
+
var inherits = require('util').inherits;
|
| 9 |
+
var Transform = require('readable-stream').Transform;
|
| 10 |
+
|
| 11 |
+
var ArchiveEntry = require('./archive-entry');
|
| 12 |
+
var util = require('../util');
|
| 13 |
+
|
| 14 |
+
var ArchiveOutputStream = module.exports = function(options) {
|
| 15 |
+
if (!(this instanceof ArchiveOutputStream)) {
|
| 16 |
+
return new ArchiveOutputStream(options);
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
Transform.call(this, options);
|
| 20 |
+
|
| 21 |
+
this.offset = 0;
|
| 22 |
+
this._archive = {
|
| 23 |
+
finish: false,
|
| 24 |
+
finished: false,
|
| 25 |
+
processing: false
|
| 26 |
+
};
|
| 27 |
+
};
|
| 28 |
+
|
| 29 |
+
inherits(ArchiveOutputStream, Transform);
|
| 30 |
+
|
| 31 |
+
ArchiveOutputStream.prototype._appendBuffer = function(zae, source, callback) {
|
| 32 |
+
// scaffold only
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
ArchiveOutputStream.prototype._appendStream = function(zae, source, callback) {
|
| 36 |
+
// scaffold only
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
ArchiveOutputStream.prototype._emitErrorCallback = function(err) {
|
| 40 |
+
if (err) {
|
| 41 |
+
this.emit('error', err);
|
| 42 |
+
}
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
ArchiveOutputStream.prototype._finish = function(ae) {
|
| 46 |
+
// scaffold only
|
| 47 |
+
};
|
| 48 |
+
|
| 49 |
+
ArchiveOutputStream.prototype._normalizeEntry = function(ae) {
|
| 50 |
+
// scaffold only
|
| 51 |
+
};
|
| 52 |
+
|
| 53 |
+
ArchiveOutputStream.prototype._transform = function(chunk, encoding, callback) {
|
| 54 |
+
callback(null, chunk);
|
| 55 |
+
};
|
| 56 |
+
|
| 57 |
+
ArchiveOutputStream.prototype.entry = function(ae, source, callback) {
|
| 58 |
+
source = source || null;
|
| 59 |
+
|
| 60 |
+
if (typeof callback !== 'function') {
|
| 61 |
+
callback = this._emitErrorCallback.bind(this);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
if (!(ae instanceof ArchiveEntry)) {
|
| 65 |
+
callback(new Error('not a valid instance of ArchiveEntry'));
|
| 66 |
+
return;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
if (this._archive.finish || this._archive.finished) {
|
| 70 |
+
callback(new Error('unacceptable entry after finish'));
|
| 71 |
+
return;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
if (this._archive.processing) {
|
| 75 |
+
callback(new Error('already processing an entry'));
|
| 76 |
+
return;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
this._archive.processing = true;
|
| 80 |
+
this._normalizeEntry(ae);
|
| 81 |
+
this._entry = ae;
|
| 82 |
+
|
| 83 |
+
source = util.normalizeInputSource(source);
|
| 84 |
+
|
| 85 |
+
if (Buffer.isBuffer(source)) {
|
| 86 |
+
this._appendBuffer(ae, source, callback);
|
| 87 |
+
} else if (util.isStream(source)) {
|
| 88 |
+
this._appendStream(ae, source, callback);
|
| 89 |
+
} else {
|
| 90 |
+
this._archive.processing = false;
|
| 91 |
+
callback(new Error('input source must be valid Stream or Buffer instance'));
|
| 92 |
+
return;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
return this;
|
| 96 |
+
};
|
| 97 |
+
|
| 98 |
+
ArchiveOutputStream.prototype.finish = function() {
|
| 99 |
+
if (this._archive.processing) {
|
| 100 |
+
this._archive.finish = true;
|
| 101 |
+
return;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
this._finish();
|
| 105 |
+
};
|
| 106 |
+
|
| 107 |
+
ArchiveOutputStream.prototype.getBytesWritten = function() {
|
| 108 |
+
return this.offset;
|
| 109 |
+
};
|
| 110 |
+
|
| 111 |
+
ArchiveOutputStream.prototype.write = function(chunk, cb) {
|
| 112 |
+
if (chunk) {
|
| 113 |
+
this.offset += chunk.length;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
return Transform.prototype.write.call(this, chunk, cb);
|
| 117 |
+
};
|
node_modules/compress-commons/lib/archivers/zip/constants.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* node-compress-commons
|
| 3 |
+
*
|
| 4 |
+
* Copyright (c) 2014 Chris Talkington, contributors.
|
| 5 |
+
* Licensed under the MIT license.
|
| 6 |
+
* https://github.com/archiverjs/node-compress-commons/blob/master/LICENSE-MIT
|
| 7 |
+
*/
|
| 8 |
+
module.exports = {
|
| 9 |
+
WORD: 4,
|
| 10 |
+
DWORD: 8,
|
| 11 |
+
EMPTY: Buffer.alloc(0),
|
| 12 |
+
|
| 13 |
+
SHORT: 2,
|
| 14 |
+
SHORT_MASK: 0xffff,
|
| 15 |
+
SHORT_SHIFT: 16,
|
| 16 |
+
SHORT_ZERO: Buffer.from(Array(2)),
|
| 17 |
+
LONG: 4,
|
| 18 |
+
LONG_ZERO: Buffer.from(Array(4)),
|
| 19 |
+
|
| 20 |
+
MIN_VERSION_INITIAL: 10,
|
| 21 |
+
MIN_VERSION_DATA_DESCRIPTOR: 20,
|
| 22 |
+
MIN_VERSION_ZIP64: 45,
|
| 23 |
+
VERSION_MADEBY: 45,
|
| 24 |
+
|
| 25 |
+
METHOD_STORED: 0,
|
| 26 |
+
METHOD_DEFLATED: 8,
|
| 27 |
+
|
| 28 |
+
PLATFORM_UNIX: 3,
|
| 29 |
+
PLATFORM_FAT: 0,
|
| 30 |
+
|
| 31 |
+
SIG_LFH: 0x04034b50,
|
| 32 |
+
SIG_DD: 0x08074b50,
|
| 33 |
+
SIG_CFH: 0x02014b50,
|
| 34 |
+
SIG_EOCD: 0x06054b50,
|
| 35 |
+
SIG_ZIP64_EOCD: 0x06064B50,
|
| 36 |
+
SIG_ZIP64_EOCD_LOC: 0x07064B50,
|
| 37 |
+
|
| 38 |
+
ZIP64_MAGIC_SHORT: 0xffff,
|
| 39 |
+
ZIP64_MAGIC: 0xffffffff,
|
| 40 |
+
ZIP64_EXTRA_ID: 0x0001,
|
| 41 |
+
|
| 42 |
+
ZLIB_NO_COMPRESSION: 0,
|
| 43 |
+
ZLIB_BEST_SPEED: 1,
|
| 44 |
+
ZLIB_BEST_COMPRESSION: 9,
|
| 45 |
+
ZLIB_DEFAULT_COMPRESSION: -1,
|
| 46 |
+
|
| 47 |
+
MODE_MASK: 0xFFF,
|
| 48 |
+
DEFAULT_FILE_MODE: 33188, // 010644 = -rw-r--r-- = S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
|
| 49 |
+
DEFAULT_DIR_MODE: 16877, // 040755 = drwxr-xr-x = S_IFDIR | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH
|
| 50 |
+
|
| 51 |
+
EXT_FILE_ATTR_DIR: 1106051088, // 010173200020 = drwxr-xr-x = (((S_IFDIR | 0755) << 16) | S_DOS_D)
|
| 52 |
+
EXT_FILE_ATTR_FILE: 2175008800, // 020151000040 = -rw-r--r-- = (((S_IFREG | 0644) << 16) | S_DOS_A) >>> 0
|
| 53 |
+
|
| 54 |
+
// Unix file types
|
| 55 |
+
S_IFMT: 61440, // 0170000 type of file mask
|
| 56 |
+
S_IFIFO: 4096, // 010000 named pipe (fifo)
|
| 57 |
+
S_IFCHR: 8192, // 020000 character special
|
| 58 |
+
S_IFDIR: 16384, // 040000 directory
|
| 59 |
+
S_IFBLK: 24576, // 060000 block special
|
| 60 |
+
S_IFREG: 32768, // 0100000 regular
|
| 61 |
+
S_IFLNK: 40960, // 0120000 symbolic link
|
| 62 |
+
S_IFSOCK: 49152, // 0140000 socket
|
| 63 |
+
|
| 64 |
+
// DOS file type flags
|
| 65 |
+
S_DOS_A: 32, // 040 Archive
|
| 66 |
+
S_DOS_D: 16, // 020 Directory
|
| 67 |
+
S_DOS_V: 8, // 010 Volume
|
| 68 |
+
S_DOS_S: 4, // 04 System
|
| 69 |
+
S_DOS_H: 2, // 02 Hidden
|
| 70 |
+
S_DOS_R: 1 // 01 Read Only
|
| 71 |
+
};
|
node_modules/compress-commons/lib/archivers/zip/general-purpose-bit.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* node-compress-commons
|
| 3 |
+
*
|
| 4 |
+
* Copyright (c) 2014 Chris Talkington, contributors.
|
| 5 |
+
* Licensed under the MIT license.
|
| 6 |
+
* https://github.com/archiverjs/node-compress-commons/blob/master/LICENSE-MIT
|
| 7 |
+
*/
|
| 8 |
+
var zipUtil = require('./util');
|
| 9 |
+
|
| 10 |
+
var DATA_DESCRIPTOR_FLAG = 1 << 3;
|
| 11 |
+
var ENCRYPTION_FLAG = 1 << 0;
|
| 12 |
+
var NUMBER_OF_SHANNON_FANO_TREES_FLAG = 1 << 2;
|
| 13 |
+
var SLIDING_DICTIONARY_SIZE_FLAG = 1 << 1;
|
| 14 |
+
var STRONG_ENCRYPTION_FLAG = 1 << 6;
|
| 15 |
+
var UFT8_NAMES_FLAG = 1 << 11;
|
| 16 |
+
|
| 17 |
+
var GeneralPurposeBit = module.exports = function() {
|
| 18 |
+
if (!(this instanceof GeneralPurposeBit)) {
|
| 19 |
+
return new GeneralPurposeBit();
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
this.descriptor = false;
|
| 23 |
+
this.encryption = false;
|
| 24 |
+
this.utf8 = false;
|
| 25 |
+
this.numberOfShannonFanoTrees = 0;
|
| 26 |
+
this.strongEncryption = false;
|
| 27 |
+
this.slidingDictionarySize = 0;
|
| 28 |
+
|
| 29 |
+
return this;
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
GeneralPurposeBit.prototype.encode = function() {
|
| 33 |
+
return zipUtil.getShortBytes(
|
| 34 |
+
(this.descriptor ? DATA_DESCRIPTOR_FLAG : 0) |
|
| 35 |
+
(this.utf8 ? UFT8_NAMES_FLAG : 0) |
|
| 36 |
+
(this.encryption ? ENCRYPTION_FLAG : 0) |
|
| 37 |
+
(this.strongEncryption ? STRONG_ENCRYPTION_FLAG : 0)
|
| 38 |
+
);
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
GeneralPurposeBit.prototype.parse = function(buf, offset) {
|
| 42 |
+
var flag = zipUtil.getShortBytesValue(buf, offset);
|
| 43 |
+
var gbp = new GeneralPurposeBit();
|
| 44 |
+
|
| 45 |
+
gbp.useDataDescriptor((flag & DATA_DESCRIPTOR_FLAG) !== 0);
|
| 46 |
+
gbp.useUTF8ForNames((flag & UFT8_NAMES_FLAG) !== 0);
|
| 47 |
+
gbp.useStrongEncryption((flag & STRONG_ENCRYPTION_FLAG) !== 0);
|
| 48 |
+
gbp.useEncryption((flag & ENCRYPTION_FLAG) !== 0);
|
| 49 |
+
gbp.setSlidingDictionarySize((flag & SLIDING_DICTIONARY_SIZE_FLAG) !== 0 ? 8192 : 4096);
|
| 50 |
+
gbp.setNumberOfShannonFanoTrees((flag & NUMBER_OF_SHANNON_FANO_TREES_FLAG) !== 0 ? 3 : 2);
|
| 51 |
+
|
| 52 |
+
return gbp;
|
| 53 |
+
};
|
| 54 |
+
|
| 55 |
+
GeneralPurposeBit.prototype.setNumberOfShannonFanoTrees = function(n) {
|
| 56 |
+
this.numberOfShannonFanoTrees = n;
|
| 57 |
+
};
|
| 58 |
+
|
| 59 |
+
GeneralPurposeBit.prototype.getNumberOfShannonFanoTrees = function() {
|
| 60 |
+
return this.numberOfShannonFanoTrees;
|
| 61 |
+
};
|
| 62 |
+
|
| 63 |
+
GeneralPurposeBit.prototype.setSlidingDictionarySize = function(n) {
|
| 64 |
+
this.slidingDictionarySize = n;
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
GeneralPurposeBit.prototype.getSlidingDictionarySize = function() {
|
| 68 |
+
return this.slidingDictionarySize;
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
GeneralPurposeBit.prototype.useDataDescriptor = function(b) {
|
| 72 |
+
this.descriptor = b;
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
GeneralPurposeBit.prototype.usesDataDescriptor = function() {
|
| 76 |
+
return this.descriptor;
|
| 77 |
+
};
|
| 78 |
+
|
| 79 |
+
GeneralPurposeBit.prototype.useEncryption = function(b) {
|
| 80 |
+
this.encryption = b;
|
| 81 |
+
};
|
| 82 |
+
|
| 83 |
+
GeneralPurposeBit.prototype.usesEncryption = function() {
|
| 84 |
+
return this.encryption;
|
| 85 |
+
};
|
| 86 |
+
|
| 87 |
+
GeneralPurposeBit.prototype.useStrongEncryption = function(b) {
|
| 88 |
+
this.strongEncryption = b;
|
| 89 |
+
};
|
| 90 |
+
|
| 91 |
+
GeneralPurposeBit.prototype.usesStrongEncryption = function() {
|
| 92 |
+
return this.strongEncryption;
|
| 93 |
+
};
|
| 94 |
+
|
| 95 |
+
GeneralPurposeBit.prototype.useUTF8ForNames = function(b) {
|
| 96 |
+
this.utf8 = b;
|
| 97 |
+
};
|
| 98 |
+
|
| 99 |
+
GeneralPurposeBit.prototype.usesUTF8ForNames = function() {
|
| 100 |
+
return this.utf8;
|
| 101 |
+
};
|
node_modules/compress-commons/lib/archivers/zip/unix-stat.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* node-compress-commons
|
| 3 |
+
*
|
| 4 |
+
* Copyright (c) 2014 Chris Talkington, contributors.
|
| 5 |
+
* Licensed under the MIT license.
|
| 6 |
+
* https://github.com/archiverjs/node-compress-commons/blob/master/LICENSE-MIT
|
| 7 |
+
*/
|
| 8 |
+
module.exports = {
|
| 9 |
+
/**
|
| 10 |
+
* Bits used for permissions (and sticky bit)
|
| 11 |
+
*/
|
| 12 |
+
PERM_MASK: 4095, // 07777
|
| 13 |
+
|
| 14 |
+
/**
|
| 15 |
+
* Bits used to indicate the filesystem object type.
|
| 16 |
+
*/
|
| 17 |
+
FILE_TYPE_FLAG: 61440, // 0170000
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* Indicates symbolic links.
|
| 21 |
+
*/
|
| 22 |
+
LINK_FLAG: 40960, // 0120000
|
| 23 |
+
|
| 24 |
+
/**
|
| 25 |
+
* Indicates plain files.
|
| 26 |
+
*/
|
| 27 |
+
FILE_FLAG: 32768, // 0100000
|
| 28 |
+
|
| 29 |
+
/**
|
| 30 |
+
* Indicates directories.
|
| 31 |
+
*/
|
| 32 |
+
DIR_FLAG: 16384, // 040000
|
| 33 |
+
|
| 34 |
+
// ----------------------------------------------------------
|
| 35 |
+
// somewhat arbitrary choices that are quite common for shared
|
| 36 |
+
// installations
|
| 37 |
+
// -----------------------------------------------------------
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Default permissions for symbolic links.
|
| 41 |
+
*/
|
| 42 |
+
DEFAULT_LINK_PERM: 511, // 0777
|
| 43 |
+
|
| 44 |
+
/**
|
| 45 |
+
* Default permissions for directories.
|
| 46 |
+
*/
|
| 47 |
+
DEFAULT_DIR_PERM: 493, // 0755
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* Default permissions for plain files.
|
| 51 |
+
*/
|
| 52 |
+
DEFAULT_FILE_PERM: 420 // 0644
|
| 53 |
+
};
|
node_modules/compress-commons/lib/archivers/zip/util.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* node-compress-commons
|
| 3 |
+
*
|
| 4 |
+
* Copyright (c) 2014 Chris Talkington, contributors.
|
| 5 |
+
* Licensed under the MIT license.
|
| 6 |
+
* https://github.com/archiverjs/node-compress-commons/blob/master/LICENSE-MIT
|
| 7 |
+
*/
|
| 8 |
+
var util = module.exports = {};
|
| 9 |
+
|
| 10 |
+
util.dateToDos = function(d, forceLocalTime) {
|
| 11 |
+
forceLocalTime = forceLocalTime || false;
|
| 12 |
+
|
| 13 |
+
var year = forceLocalTime ? d.getFullYear() : d.getUTCFullYear();
|
| 14 |
+
|
| 15 |
+
if (year < 1980) {
|
| 16 |
+
return 2162688; // 1980-1-1 00:00:00
|
| 17 |
+
} else if (year >= 2044) {
|
| 18 |
+
return 2141175677; // 2043-12-31 23:59:58
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
var val = {
|
| 22 |
+
year: year,
|
| 23 |
+
month: forceLocalTime ? d.getMonth() : d.getUTCMonth(),
|
| 24 |
+
date: forceLocalTime ? d.getDate() : d.getUTCDate(),
|
| 25 |
+
hours: forceLocalTime ? d.getHours() : d.getUTCHours(),
|
| 26 |
+
minutes: forceLocalTime ? d.getMinutes() : d.getUTCMinutes(),
|
| 27 |
+
seconds: forceLocalTime ? d.getSeconds() : d.getUTCSeconds()
|
| 28 |
+
};
|
| 29 |
+
|
| 30 |
+
return ((val.year - 1980) << 25) | ((val.month + 1) << 21) | (val.date << 16) |
|
| 31 |
+
(val.hours << 11) | (val.minutes << 5) | (val.seconds / 2);
|
| 32 |
+
};
|
| 33 |
+
|
| 34 |
+
util.dosToDate = function(dos) {
|
| 35 |
+
return new Date(((dos >> 25) & 0x7f) + 1980, ((dos >> 21) & 0x0f) - 1, (dos >> 16) & 0x1f, (dos >> 11) & 0x1f, (dos >> 5) & 0x3f, (dos & 0x1f) << 1);
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
util.fromDosTime = function(buf) {
|
| 39 |
+
return util.dosToDate(buf.readUInt32LE(0));
|
| 40 |
+
};
|
| 41 |
+
|
| 42 |
+
util.getEightBytes = function(v) {
|
| 43 |
+
var buf = Buffer.alloc(8);
|
| 44 |
+
buf.writeUInt32LE(v % 0x0100000000, 0);
|
| 45 |
+
buf.writeUInt32LE((v / 0x0100000000) | 0, 4);
|
| 46 |
+
|
| 47 |
+
return buf;
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
util.getShortBytes = function(v) {
|
| 51 |
+
var buf = Buffer.alloc(2);
|
| 52 |
+
buf.writeUInt16LE((v & 0xFFFF) >>> 0, 0);
|
| 53 |
+
|
| 54 |
+
return buf;
|
| 55 |
+
};
|
| 56 |
+
|
| 57 |
+
util.getShortBytesValue = function(buf, offset) {
|
| 58 |
+
return buf.readUInt16LE(offset);
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
util.getLongBytes = function(v) {
|
| 62 |
+
var buf = Buffer.alloc(4);
|
| 63 |
+
buf.writeUInt32LE((v & 0xFFFFFFFF) >>> 0, 0);
|
| 64 |
+
|
| 65 |
+
return buf;
|
| 66 |
+
};
|
| 67 |
+
|
| 68 |
+
util.getLongBytesValue = function(buf, offset) {
|
| 69 |
+
return buf.readUInt32LE(offset);
|
| 70 |
+
};
|
| 71 |
+
|
| 72 |
+
util.toDosTime = function(d) {
|
| 73 |
+
return util.getLongBytes(util.dateToDos(d));
|
| 74 |
+
};
|
node_modules/compress-commons/lib/archivers/zip/zip-archive-entry.js
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
| 6 |
+
* https://github.com/archiverjs/node-compress-commons/blob/master/LICENSE-MIT
|
| 7 |
+
*/
|
| 8 |
+
var inherits = require('util').inherits;
|
| 9 |
+
var normalizePath = require('normalize-path');
|
| 10 |
+
|
| 11 |
+
var ArchiveEntry = require('../archive-entry');
|
| 12 |
+
var GeneralPurposeBit = require('./general-purpose-bit');
|
| 13 |
+
var UnixStat = require('./unix-stat');
|
| 14 |
+
|
| 15 |
+
var constants = require('./constants');
|
| 16 |
+
var zipUtil = require('./util');
|
| 17 |
+
|
| 18 |
+
var ZipArchiveEntry = module.exports = function(name) {
|
| 19 |
+
if (!(this instanceof ZipArchiveEntry)) {
|
| 20 |
+
return new ZipArchiveEntry(name);
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
ArchiveEntry.call(this);
|
| 24 |
+
|
| 25 |
+
this.platform = constants.PLATFORM_FAT;
|
| 26 |
+
this.method = -1;
|
| 27 |
+
|
| 28 |
+
this.name = null;
|
| 29 |
+
this.size = 0;
|
| 30 |
+
this.csize = 0;
|
| 31 |
+
this.gpb = new GeneralPurposeBit();
|
| 32 |
+
this.crc = 0;
|
| 33 |
+
this.time = -1;
|
| 34 |
+
|
| 35 |
+
this.minver = constants.MIN_VERSION_INITIAL;
|
| 36 |
+
this.mode = -1;
|
| 37 |
+
this.extra = null;
|
| 38 |
+
this.exattr = 0;
|
| 39 |
+
this.inattr = 0;
|
| 40 |
+
this.comment = null;
|
| 41 |
+
|
| 42 |
+
if (name) {
|
| 43 |
+
this.setName(name);
|
| 44 |
+
}
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
inherits(ZipArchiveEntry, ArchiveEntry);
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* Returns the extra fields related to the entry.
|
| 51 |
+
*
|
| 52 |
+
* @returns {Buffer}
|
| 53 |
+
*/
|
| 54 |
+
ZipArchiveEntry.prototype.getCentralDirectoryExtra = function() {
|
| 55 |
+
return this.getExtra();
|
| 56 |
+
};
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Returns the comment set for the entry.
|
| 60 |
+
*
|
| 61 |
+
* @returns {string}
|
| 62 |
+
*/
|
| 63 |
+
ZipArchiveEntry.prototype.getComment = function() {
|
| 64 |
+
return this.comment !== null ? this.comment : '';
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
/**
|
| 68 |
+
* Returns the compressed size of the entry.
|
| 69 |
+
*
|
| 70 |
+
* @returns {number}
|
| 71 |
+
*/
|
| 72 |
+
ZipArchiveEntry.prototype.getCompressedSize = function() {
|
| 73 |
+
return this.csize;
|
| 74 |
+
};
|
| 75 |
+
|
| 76 |
+
/**
|
| 77 |
+
* Returns the CRC32 digest for the entry.
|
| 78 |
+
*
|
| 79 |
+
* @returns {number}
|
| 80 |
+
*/
|
| 81 |
+
ZipArchiveEntry.prototype.getCrc = function() {
|
| 82 |
+
return this.crc;
|
| 83 |
+
};
|
| 84 |
+
|
| 85 |
+
/**
|
| 86 |
+
* Returns the external file attributes for the entry.
|
| 87 |
+
*
|
| 88 |
+
* @returns {number}
|
| 89 |
+
*/
|
| 90 |
+
ZipArchiveEntry.prototype.getExternalAttributes = function() {
|
| 91 |
+
return this.exattr;
|
| 92 |
+
};
|
| 93 |
+
|
| 94 |
+
/**
|
| 95 |
+
* Returns the extra fields related to the entry.
|
| 96 |
+
*
|
| 97 |
+
* @returns {Buffer}
|
| 98 |
+
*/
|
| 99 |
+
ZipArchiveEntry.prototype.getExtra = function() {
|
| 100 |
+
return this.extra !== null ? this.extra : constants.EMPTY;
|
| 101 |
+
};
|
| 102 |
+
|
| 103 |
+
/**
|
| 104 |
+
* Returns the general purpose bits related to the entry.
|
| 105 |
+
*
|
| 106 |
+
* @returns {GeneralPurposeBit}
|
| 107 |
+
*/
|
| 108 |
+
ZipArchiveEntry.prototype.getGeneralPurposeBit = function() {
|
| 109 |
+
return this.gpb;
|
| 110 |
+
};
|
| 111 |
+
|
| 112 |
+
/**
|
| 113 |
+
* Returns the internal file attributes for the entry.
|
| 114 |
+
*
|
| 115 |
+
* @returns {number}
|
| 116 |
+
*/
|
| 117 |
+
ZipArchiveEntry.prototype.getInternalAttributes = function() {
|
| 118 |
+
return this.inattr;
|
| 119 |
+
};
|
| 120 |
+
|
| 121 |
+
/**
|
| 122 |
+
* Returns the last modified date of the entry.
|
| 123 |
+
*
|
| 124 |
+
* @returns {number}
|
| 125 |
+
*/
|
| 126 |
+
ZipArchiveEntry.prototype.getLastModifiedDate = function() {
|
| 127 |
+
return this.getTime();
|
| 128 |
+
};
|
| 129 |
+
|
| 130 |
+
/**
|
| 131 |
+
* Returns the extra fields related to the entry.
|
| 132 |
+
*
|
| 133 |
+
* @returns {Buffer}
|
| 134 |
+
*/
|
| 135 |
+
ZipArchiveEntry.prototype.getLocalFileDataExtra = function() {
|
| 136 |
+
return this.getExtra();
|
| 137 |
+
};
|
| 138 |
+
|
| 139 |
+
/**
|
| 140 |
+
* Returns the compression method used on the entry.
|
| 141 |
+
*
|
| 142 |
+
* @returns {number}
|
| 143 |
+
*/
|
| 144 |
+
ZipArchiveEntry.prototype.getMethod = function() {
|
| 145 |
+
return this.method;
|
| 146 |
+
};
|
| 147 |
+
|
| 148 |
+
/**
|
| 149 |
+
* Returns the filename of the entry.
|
| 150 |
+
*
|
| 151 |
+
* @returns {string}
|
| 152 |
+
*/
|
| 153 |
+
ZipArchiveEntry.prototype.getName = function() {
|
| 154 |
+
return this.name;
|
| 155 |
+
};
|
| 156 |
+
|
| 157 |
+
/**
|
| 158 |
+
* Returns the platform on which the entry was made.
|
| 159 |
+
*
|
| 160 |
+
* @returns {number}
|
| 161 |
+
*/
|
| 162 |
+
ZipArchiveEntry.prototype.getPlatform = function() {
|
| 163 |
+
return this.platform;
|
| 164 |
+
};
|
| 165 |
+
|
| 166 |
+
/**
|
| 167 |
+
* Returns the size of the entry.
|
| 168 |
+
*
|
| 169 |
+
* @returns {number}
|
| 170 |
+
*/
|
| 171 |
+
ZipArchiveEntry.prototype.getSize = function() {
|
| 172 |
+
return this.size;
|
| 173 |
+
};
|
| 174 |
+
|
| 175 |
+
/**
|
| 176 |
+
* Returns a date object representing the last modified date of the entry.
|
| 177 |
+
*
|
| 178 |
+
* @returns {number|Date}
|
| 179 |
+
*/
|
| 180 |
+
ZipArchiveEntry.prototype.getTime = function() {
|
| 181 |
+
return this.time !== -1 ? zipUtil.dosToDate(this.time) : -1;
|
| 182 |
+
};
|
| 183 |
+
|
| 184 |
+
/**
|
| 185 |
+
* Returns the DOS timestamp for the entry.
|
| 186 |
+
*
|
| 187 |
+
* @returns {number}
|
| 188 |
+
*/
|
| 189 |
+
ZipArchiveEntry.prototype.getTimeDos = function() {
|
| 190 |
+
return this.time !== -1 ? this.time : 0;
|
| 191 |
+
};
|
| 192 |
+
|
| 193 |
+
/**
|
| 194 |
+
* Returns the UNIX file permissions for the entry.
|
| 195 |
+
*
|
| 196 |
+
* @returns {number}
|
| 197 |
+
*/
|
| 198 |
+
ZipArchiveEntry.prototype.getUnixMode = function() {
|
| 199 |
+
return this.platform !== constants.PLATFORM_UNIX ? 0 : ((this.getExternalAttributes() >> constants.SHORT_SHIFT) & constants.SHORT_MASK);
|
| 200 |
+
};
|
| 201 |
+
|
| 202 |
+
/**
|
| 203 |
+
* Returns the version of ZIP needed to extract the entry.
|
| 204 |
+
*
|
| 205 |
+
* @returns {number}
|
| 206 |
+
*/
|
| 207 |
+
ZipArchiveEntry.prototype.getVersionNeededToExtract = function() {
|
| 208 |
+
return this.minver;
|
| 209 |
+
};
|
| 210 |
+
|
| 211 |
+
/**
|
| 212 |
+
* Sets the comment of the entry.
|
| 213 |
+
*
|
| 214 |
+
* @param comment
|
| 215 |
+
*/
|
| 216 |
+
ZipArchiveEntry.prototype.setComment = function(comment) {
|
| 217 |
+
if (Buffer.byteLength(comment) !== comment.length) {
|
| 218 |
+
this.getGeneralPurposeBit().useUTF8ForNames(true);
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
this.comment = comment;
|
| 222 |
+
};
|
| 223 |
+
|
| 224 |
+
/**
|
| 225 |
+
* Sets the compressed size of the entry.
|
| 226 |
+
*
|
| 227 |
+
* @param size
|
| 228 |
+
*/
|
| 229 |
+
ZipArchiveEntry.prototype.setCompressedSize = function(size) {
|
| 230 |
+
if (size < 0) {
|
| 231 |
+
throw new Error('invalid entry compressed size');
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
this.csize = size;
|
| 235 |
+
};
|
| 236 |
+
|
| 237 |
+
/**
|
| 238 |
+
* Sets the checksum of the entry.
|
| 239 |
+
*
|
| 240 |
+
* @param crc
|
| 241 |
+
*/
|
| 242 |
+
ZipArchiveEntry.prototype.setCrc = function(crc) {
|
| 243 |
+
if (crc < 0) {
|
| 244 |
+
throw new Error('invalid entry crc32');
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
this.crc = crc;
|
| 248 |
+
};
|
| 249 |
+
|
| 250 |
+
/**
|
| 251 |
+
* Sets the external file attributes of the entry.
|
| 252 |
+
*
|
| 253 |
+
* @param attr
|
| 254 |
+
*/
|
| 255 |
+
ZipArchiveEntry.prototype.setExternalAttributes = function(attr) {
|
| 256 |
+
this.exattr = attr >>> 0;
|
| 257 |
+
};
|
| 258 |
+
|
| 259 |
+
/**
|
| 260 |
+
* Sets the extra fields related to the entry.
|
| 261 |
+
*
|
| 262 |
+
* @param extra
|
| 263 |
+
*/
|
| 264 |
+
ZipArchiveEntry.prototype.setExtra = function(extra) {
|
| 265 |
+
this.extra = extra;
|
| 266 |
+
};
|
| 267 |
+
|
| 268 |
+
/**
|
| 269 |
+
* Sets the general purpose bits related to the entry.
|
| 270 |
+
*
|
| 271 |
+
* @param gpb
|
| 272 |
+
*/
|
| 273 |
+
ZipArchiveEntry.prototype.setGeneralPurposeBit = function(gpb) {
|
| 274 |
+
if (!(gpb instanceof GeneralPurposeBit)) {
|
| 275 |
+
throw new Error('invalid entry GeneralPurposeBit');
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
this.gpb = gpb;
|
| 279 |
+
};
|
| 280 |
+
|
| 281 |
+
/**
|
| 282 |
+
* Sets the internal file attributes of the entry.
|
| 283 |
+
*
|
| 284 |
+
* @param attr
|
| 285 |
+
*/
|
| 286 |
+
ZipArchiveEntry.prototype.setInternalAttributes = function(attr) {
|
| 287 |
+
this.inattr = attr;
|
| 288 |
+
};
|
| 289 |
+
|
| 290 |
+
/**
|
| 291 |
+
* Sets the compression method of the entry.
|
| 292 |
+
*
|
| 293 |
+
* @param method
|
| 294 |
+
*/
|
| 295 |
+
ZipArchiveEntry.prototype.setMethod = function(method) {
|
| 296 |
+
if (method < 0) {
|
| 297 |
+
throw new Error('invalid entry compression method');
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
this.method = method;
|
| 301 |
+
};
|
| 302 |
+
|
| 303 |
+
/**
|
| 304 |
+
* Sets the name of the entry.
|
| 305 |
+
*
|
| 306 |
+
* @param name
|
| 307 |
+
* @param prependSlash
|
| 308 |
+
*/
|
| 309 |
+
ZipArchiveEntry.prototype.setName = function(name, prependSlash = false) {
|
| 310 |
+
name = normalizePath(name, false)
|
| 311 |
+
.replace(/^\w+:/, '')
|
| 312 |
+
.replace(/^(\.\.\/|\/)+/, '');
|
| 313 |
+
|
| 314 |
+
if (prependSlash) {
|
| 315 |
+
name = `/${name}`;
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
if (Buffer.byteLength(name) !== name.length) {
|
| 319 |
+
this.getGeneralPurposeBit().useUTF8ForNames(true);
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
this.name = name;
|
| 323 |
+
};
|
| 324 |
+
|
| 325 |
+
/**
|
| 326 |
+
* Sets the platform on which the entry was made.
|
| 327 |
+
*
|
| 328 |
+
* @param platform
|
| 329 |
+
*/
|
| 330 |
+
ZipArchiveEntry.prototype.setPlatform = function(platform) {
|
| 331 |
+
this.platform = platform;
|
| 332 |
+
};
|
| 333 |
+
|
| 334 |
+
/**
|
| 335 |
+
* Sets the size of the entry.
|
| 336 |
+
*
|
| 337 |
+
* @param size
|
| 338 |
+
*/
|
| 339 |
+
ZipArchiveEntry.prototype.setSize = function(size) {
|
| 340 |
+
if (size < 0) {
|
| 341 |
+
throw new Error('invalid entry size');
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
this.size = size;
|
| 345 |
+
};
|
| 346 |
+
|
| 347 |
+
/**
|
| 348 |
+
* Sets the time of the entry.
|
| 349 |
+
*
|
| 350 |
+
* @param time
|
| 351 |
+
* @param forceLocalTime
|
| 352 |
+
*/
|
| 353 |
+
ZipArchiveEntry.prototype.setTime = function(time, forceLocalTime) {
|
| 354 |
+
if (!(time instanceof Date)) {
|
| 355 |
+
throw new Error('invalid entry time');
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
this.time = zipUtil.dateToDos(time, forceLocalTime);
|
| 359 |
+
};
|
| 360 |
+
|
| 361 |
+
/**
|
| 362 |
+
* Sets the UNIX file permissions for the entry.
|
| 363 |
+
*
|
| 364 |
+
* @param mode
|
| 365 |
+
*/
|
| 366 |
+
ZipArchiveEntry.prototype.setUnixMode = function(mode) {
|
| 367 |
+
mode |= this.isDirectory() ? constants.S_IFDIR : constants.S_IFREG;
|
| 368 |
+
|
| 369 |
+
var extattr = 0;
|
| 370 |
+
extattr |= (mode << constants.SHORT_SHIFT) | (this.isDirectory() ? constants.S_DOS_D : constants.S_DOS_A);
|
| 371 |
+
|
| 372 |
+
this.setExternalAttributes(extattr);
|
| 373 |
+
this.mode = mode & constants.MODE_MASK;
|
| 374 |
+
this.platform = constants.PLATFORM_UNIX;
|
| 375 |
+
};
|
| 376 |
+
|
| 377 |
+
/**
|
| 378 |
+
* Sets the version of ZIP needed to extract this entry.
|
| 379 |
+
*
|
| 380 |
+
* @param minver
|
| 381 |
+
*/
|
| 382 |
+
ZipArchiveEntry.prototype.setVersionNeededToExtract = function(minver) {
|
| 383 |
+
this.minver = minver;
|
| 384 |
+
};
|
| 385 |
+
|
| 386 |
+
/**
|
| 387 |
+
* Returns true if this entry represents a directory.
|
| 388 |
+
*
|
| 389 |
+
* @returns {boolean}
|
| 390 |
+
*/
|
| 391 |
+
ZipArchiveEntry.prototype.isDirectory = function() {
|
| 392 |
+
return this.getName().slice(-1) === '/';
|
| 393 |
+
};
|
| 394 |
+
|
| 395 |
+
/**
|
| 396 |
+
* Returns true if this entry represents a unix symlink,
|
| 397 |
+
* in which case the entry's content contains the target path
|
| 398 |
+
* for the symlink.
|
| 399 |
+
*
|
| 400 |
+
* @returns {boolean}
|
| 401 |
+
*/
|
| 402 |
+
ZipArchiveEntry.prototype.isUnixSymlink = function() {
|
| 403 |
+
return (this.getUnixMode() & UnixStat.FILE_TYPE_FLAG) === UnixStat.LINK_FLAG;
|
| 404 |
+
};
|
| 405 |
+
|
| 406 |
+
/**
|
| 407 |
+
* Returns true if this entry is using the ZIP64 extension of ZIP.
|
| 408 |
+
*
|
| 409 |
+
* @returns {boolean}
|
| 410 |
+
*/
|
| 411 |
+
ZipArchiveEntry.prototype.isZip64 = function() {
|
| 412 |
+
return this.csize > constants.ZIP64_MAGIC || this.size > constants.ZIP64_MAGIC;
|
| 413 |
+
};
|
node_modules/compress-commons/lib/archivers/zip/zip-archive-output-stream.js
ADDED
|
@@ -0,0 +1,437 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* node-compress-commons
|
| 3 |
+
*
|
| 4 |
+
* Copyright (c) 2014 Chris Talkington, contributors.
|
| 5 |
+
* Licensed under the MIT license.
|
| 6 |
+
* https://github.com/archiverjs/node-compress-commons/blob/master/LICENSE-MIT
|
| 7 |
+
*/
|
| 8 |
+
var inherits = require('util').inherits;
|
| 9 |
+
var crc32 = require('crc-32');
|
| 10 |
+
var {CRC32Stream} = require('crc32-stream');
|
| 11 |
+
var {DeflateCRC32Stream} = require('crc32-stream');
|
| 12 |
+
|
| 13 |
+
var ArchiveOutputStream = require('../archive-output-stream');
|
| 14 |
+
var ZipArchiveEntry = require('./zip-archive-entry');
|
| 15 |
+
var GeneralPurposeBit = require('./general-purpose-bit');
|
| 16 |
+
|
| 17 |
+
var constants = require('./constants');
|
| 18 |
+
var util = require('../../util');
|
| 19 |
+
var zipUtil = require('./util');
|
| 20 |
+
|
| 21 |
+
var ZipArchiveOutputStream = module.exports = function(options) {
|
| 22 |
+
if (!(this instanceof ZipArchiveOutputStream)) {
|
| 23 |
+
return new ZipArchiveOutputStream(options);
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
options = this.options = this._defaults(options);
|
| 27 |
+
|
| 28 |
+
ArchiveOutputStream.call(this, options);
|
| 29 |
+
|
| 30 |
+
this._entry = null;
|
| 31 |
+
this._entries = [];
|
| 32 |
+
this._archive = {
|
| 33 |
+
centralLength: 0,
|
| 34 |
+
centralOffset: 0,
|
| 35 |
+
comment: '',
|
| 36 |
+
finish: false,
|
| 37 |
+
finished: false,
|
| 38 |
+
processing: false,
|
| 39 |
+
forceZip64: options.forceZip64,
|
| 40 |
+
forceLocalTime: options.forceLocalTime
|
| 41 |
+
};
|
| 42 |
+
};
|
| 43 |
+
|
| 44 |
+
inherits(ZipArchiveOutputStream, ArchiveOutputStream);
|
| 45 |
+
|
| 46 |
+
ZipArchiveOutputStream.prototype._afterAppend = function(ae) {
|
| 47 |
+
this._entries.push(ae);
|
| 48 |
+
|
| 49 |
+
if (ae.getGeneralPurposeBit().usesDataDescriptor()) {
|
| 50 |
+
this._writeDataDescriptor(ae);
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
this._archive.processing = false;
|
| 54 |
+
this._entry = null;
|
| 55 |
+
|
| 56 |
+
if (this._archive.finish && !this._archive.finished) {
|
| 57 |
+
this._finish();
|
| 58 |
+
}
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
ZipArchiveOutputStream.prototype._appendBuffer = function(ae, source, callback) {
|
| 62 |
+
if (source.length === 0) {
|
| 63 |
+
ae.setMethod(constants.METHOD_STORED);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
var method = ae.getMethod();
|
| 67 |
+
|
| 68 |
+
if (method === constants.METHOD_STORED) {
|
| 69 |
+
ae.setSize(source.length);
|
| 70 |
+
ae.setCompressedSize(source.length);
|
| 71 |
+
ae.setCrc(crc32.buf(source) >>> 0);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
this._writeLocalFileHeader(ae);
|
| 75 |
+
|
| 76 |
+
if (method === constants.METHOD_STORED) {
|
| 77 |
+
this.write(source);
|
| 78 |
+
this._afterAppend(ae);
|
| 79 |
+
callback(null, ae);
|
| 80 |
+
return;
|
| 81 |
+
} else if (method === constants.METHOD_DEFLATED) {
|
| 82 |
+
this._smartStream(ae, callback).end(source);
|
| 83 |
+
return;
|
| 84 |
+
} else {
|
| 85 |
+
callback(new Error('compression method ' + method + ' not implemented'));
|
| 86 |
+
return;
|
| 87 |
+
}
|
| 88 |
+
};
|
| 89 |
+
|
| 90 |
+
ZipArchiveOutputStream.prototype._appendStream = function(ae, source, callback) {
|
| 91 |
+
ae.getGeneralPurposeBit().useDataDescriptor(true);
|
| 92 |
+
ae.setVersionNeededToExtract(constants.MIN_VERSION_DATA_DESCRIPTOR);
|
| 93 |
+
|
| 94 |
+
this._writeLocalFileHeader(ae);
|
| 95 |
+
|
| 96 |
+
var smart = this._smartStream(ae, callback);
|
| 97 |
+
source.once('error', function(err) {
|
| 98 |
+
smart.emit('error', err);
|
| 99 |
+
smart.end();
|
| 100 |
+
})
|
| 101 |
+
source.pipe(smart);
|
| 102 |
+
};
|
| 103 |
+
|
| 104 |
+
ZipArchiveOutputStream.prototype._defaults = function(o) {
|
| 105 |
+
if (typeof o !== 'object') {
|
| 106 |
+
o = {};
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
if (typeof o.zlib !== 'object') {
|
| 110 |
+
o.zlib = {};
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
if (typeof o.zlib.level !== 'number') {
|
| 114 |
+
o.zlib.level = constants.ZLIB_BEST_SPEED;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
o.forceZip64 = !!o.forceZip64;
|
| 118 |
+
o.forceLocalTime = !!o.forceLocalTime;
|
| 119 |
+
|
| 120 |
+
return o;
|
| 121 |
+
};
|
| 122 |
+
|
| 123 |
+
ZipArchiveOutputStream.prototype._finish = function() {
|
| 124 |
+
this._archive.centralOffset = this.offset;
|
| 125 |
+
|
| 126 |
+
this._entries.forEach(function(ae) {
|
| 127 |
+
this._writeCentralFileHeader(ae);
|
| 128 |
+
}.bind(this));
|
| 129 |
+
|
| 130 |
+
this._archive.centralLength = this.offset - this._archive.centralOffset;
|
| 131 |
+
|
| 132 |
+
if (this.isZip64()) {
|
| 133 |
+
this._writeCentralDirectoryZip64();
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
this._writeCentralDirectoryEnd();
|
| 137 |
+
|
| 138 |
+
this._archive.processing = false;
|
| 139 |
+
this._archive.finish = true;
|
| 140 |
+
this._archive.finished = true;
|
| 141 |
+
this.end();
|
| 142 |
+
};
|
| 143 |
+
|
| 144 |
+
ZipArchiveOutputStream.prototype._normalizeEntry = function(ae) {
|
| 145 |
+
if (ae.getMethod() === -1) {
|
| 146 |
+
ae.setMethod(constants.METHOD_DEFLATED);
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
if (ae.getMethod() === constants.METHOD_DEFLATED) {
|
| 150 |
+
ae.getGeneralPurposeBit().useDataDescriptor(true);
|
| 151 |
+
ae.setVersionNeededToExtract(constants.MIN_VERSION_DATA_DESCRIPTOR);
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
if (ae.getTime() === -1) {
|
| 155 |
+
ae.setTime(new Date(), this._archive.forceLocalTime);
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
ae._offsets = {
|
| 159 |
+
file: 0,
|
| 160 |
+
data: 0,
|
| 161 |
+
contents: 0,
|
| 162 |
+
};
|
| 163 |
+
};
|
| 164 |
+
|
| 165 |
+
ZipArchiveOutputStream.prototype._smartStream = function(ae, callback) {
|
| 166 |
+
var deflate = ae.getMethod() === constants.METHOD_DEFLATED;
|
| 167 |
+
var process = deflate ? new DeflateCRC32Stream(this.options.zlib) : new CRC32Stream();
|
| 168 |
+
var error = null;
|
| 169 |
+
|
| 170 |
+
function handleStuff() {
|
| 171 |
+
var digest = process.digest().readUInt32BE(0);
|
| 172 |
+
ae.setCrc(digest);
|
| 173 |
+
ae.setSize(process.size());
|
| 174 |
+
ae.setCompressedSize(process.size(true));
|
| 175 |
+
this._afterAppend(ae);
|
| 176 |
+
callback(error, ae);
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
process.once('end', handleStuff.bind(this));
|
| 180 |
+
process.once('error', function(err) {
|
| 181 |
+
error = err;
|
| 182 |
+
});
|
| 183 |
+
|
| 184 |
+
process.pipe(this, { end: false });
|
| 185 |
+
|
| 186 |
+
return process;
|
| 187 |
+
};
|
| 188 |
+
|
| 189 |
+
ZipArchiveOutputStream.prototype._writeCentralDirectoryEnd = function() {
|
| 190 |
+
var records = this._entries.length;
|
| 191 |
+
var size = this._archive.centralLength;
|
| 192 |
+
var offset = this._archive.centralOffset;
|
| 193 |
+
|
| 194 |
+
if (this.isZip64()) {
|
| 195 |
+
records = constants.ZIP64_MAGIC_SHORT;
|
| 196 |
+
size = constants.ZIP64_MAGIC;
|
| 197 |
+
offset = constants.ZIP64_MAGIC;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
// signature
|
| 201 |
+
this.write(zipUtil.getLongBytes(constants.SIG_EOCD));
|
| 202 |
+
|
| 203 |
+
// disk numbers
|
| 204 |
+
this.write(constants.SHORT_ZERO);
|
| 205 |
+
this.write(constants.SHORT_ZERO);
|
| 206 |
+
|
| 207 |
+
// number of entries
|
| 208 |
+
this.write(zipUtil.getShortBytes(records));
|
| 209 |
+
this.write(zipUtil.getShortBytes(records));
|
| 210 |
+
|
| 211 |
+
// length and location of CD
|
| 212 |
+
this.write(zipUtil.getLongBytes(size));
|
| 213 |
+
this.write(zipUtil.getLongBytes(offset));
|
| 214 |
+
|
| 215 |
+
// archive comment
|
| 216 |
+
var comment = this.getComment();
|
| 217 |
+
var commentLength = Buffer.byteLength(comment);
|
| 218 |
+
this.write(zipUtil.getShortBytes(commentLength));
|
| 219 |
+
this.write(comment);
|
| 220 |
+
};
|
| 221 |
+
|
| 222 |
+
ZipArchiveOutputStream.prototype._writeCentralDirectoryZip64 = function() {
|
| 223 |
+
// signature
|
| 224 |
+
this.write(zipUtil.getLongBytes(constants.SIG_ZIP64_EOCD));
|
| 225 |
+
|
| 226 |
+
// size of the ZIP64 EOCD record
|
| 227 |
+
this.write(zipUtil.getEightBytes(44));
|
| 228 |
+
|
| 229 |
+
// version made by
|
| 230 |
+
this.write(zipUtil.getShortBytes(constants.MIN_VERSION_ZIP64));
|
| 231 |
+
|
| 232 |
+
// version to extract
|
| 233 |
+
this.write(zipUtil.getShortBytes(constants.MIN_VERSION_ZIP64));
|
| 234 |
+
|
| 235 |
+
// disk numbers
|
| 236 |
+
this.write(constants.LONG_ZERO);
|
| 237 |
+
this.write(constants.LONG_ZERO);
|
| 238 |
+
|
| 239 |
+
// number of entries
|
| 240 |
+
this.write(zipUtil.getEightBytes(this._entries.length));
|
| 241 |
+
this.write(zipUtil.getEightBytes(this._entries.length));
|
| 242 |
+
|
| 243 |
+
// length and location of CD
|
| 244 |
+
this.write(zipUtil.getEightBytes(this._archive.centralLength));
|
| 245 |
+
this.write(zipUtil.getEightBytes(this._archive.centralOffset));
|
| 246 |
+
|
| 247 |
+
// extensible data sector
|
| 248 |
+
// not implemented at this time
|
| 249 |
+
|
| 250 |
+
// end of central directory locator
|
| 251 |
+
this.write(zipUtil.getLongBytes(constants.SIG_ZIP64_EOCD_LOC));
|
| 252 |
+
|
| 253 |
+
// disk number holding the ZIP64 EOCD record
|
| 254 |
+
this.write(constants.LONG_ZERO);
|
| 255 |
+
|
| 256 |
+
// relative offset of the ZIP64 EOCD record
|
| 257 |
+
this.write(zipUtil.getEightBytes(this._archive.centralOffset + this._archive.centralLength));
|
| 258 |
+
|
| 259 |
+
// total number of disks
|
| 260 |
+
this.write(zipUtil.getLongBytes(1));
|
| 261 |
+
};
|
| 262 |
+
|
| 263 |
+
ZipArchiveOutputStream.prototype._writeCentralFileHeader = function(ae) {
|
| 264 |
+
var gpb = ae.getGeneralPurposeBit();
|
| 265 |
+
var method = ae.getMethod();
|
| 266 |
+
var fileOffset = ae._offsets.file;
|
| 267 |
+
|
| 268 |
+
var size = ae.getSize();
|
| 269 |
+
var compressedSize = ae.getCompressedSize();
|
| 270 |
+
|
| 271 |
+
if (ae.isZip64() || fileOffset > constants.ZIP64_MAGIC) {
|
| 272 |
+
size = constants.ZIP64_MAGIC;
|
| 273 |
+
compressedSize = constants.ZIP64_MAGIC;
|
| 274 |
+
fileOffset = constants.ZIP64_MAGIC;
|
| 275 |
+
|
| 276 |
+
ae.setVersionNeededToExtract(constants.MIN_VERSION_ZIP64);
|
| 277 |
+
|
| 278 |
+
var extraBuf = Buffer.concat([
|
| 279 |
+
zipUtil.getShortBytes(constants.ZIP64_EXTRA_ID),
|
| 280 |
+
zipUtil.getShortBytes(24),
|
| 281 |
+
zipUtil.getEightBytes(ae.getSize()),
|
| 282 |
+
zipUtil.getEightBytes(ae.getCompressedSize()),
|
| 283 |
+
zipUtil.getEightBytes(ae._offsets.file)
|
| 284 |
+
], 28);
|
| 285 |
+
|
| 286 |
+
ae.setExtra(extraBuf);
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
// signature
|
| 290 |
+
this.write(zipUtil.getLongBytes(constants.SIG_CFH));
|
| 291 |
+
|
| 292 |
+
// version made by
|
| 293 |
+
this.write(zipUtil.getShortBytes((ae.getPlatform() << 8) | constants.VERSION_MADEBY));
|
| 294 |
+
|
| 295 |
+
// version to extract and general bit flag
|
| 296 |
+
this.write(zipUtil.getShortBytes(ae.getVersionNeededToExtract()));
|
| 297 |
+
this.write(gpb.encode());
|
| 298 |
+
|
| 299 |
+
// compression method
|
| 300 |
+
this.write(zipUtil.getShortBytes(method));
|
| 301 |
+
|
| 302 |
+
// datetime
|
| 303 |
+
this.write(zipUtil.getLongBytes(ae.getTimeDos()));
|
| 304 |
+
|
| 305 |
+
// crc32 checksum
|
| 306 |
+
this.write(zipUtil.getLongBytes(ae.getCrc()));
|
| 307 |
+
|
| 308 |
+
// sizes
|
| 309 |
+
this.write(zipUtil.getLongBytes(compressedSize));
|
| 310 |
+
this.write(zipUtil.getLongBytes(size));
|
| 311 |
+
|
| 312 |
+
var name = ae.getName();
|
| 313 |
+
var comment = ae.getComment();
|
| 314 |
+
var extra = ae.getCentralDirectoryExtra();
|
| 315 |
+
|
| 316 |
+
if (gpb.usesUTF8ForNames()) {
|
| 317 |
+
name = Buffer.from(name);
|
| 318 |
+
comment = Buffer.from(comment);
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
// name length
|
| 322 |
+
this.write(zipUtil.getShortBytes(name.length));
|
| 323 |
+
|
| 324 |
+
// extra length
|
| 325 |
+
this.write(zipUtil.getShortBytes(extra.length));
|
| 326 |
+
|
| 327 |
+
// comments length
|
| 328 |
+
this.write(zipUtil.getShortBytes(comment.length));
|
| 329 |
+
|
| 330 |
+
// disk number start
|
| 331 |
+
this.write(constants.SHORT_ZERO);
|
| 332 |
+
|
| 333 |
+
// internal attributes
|
| 334 |
+
this.write(zipUtil.getShortBytes(ae.getInternalAttributes()));
|
| 335 |
+
|
| 336 |
+
// external attributes
|
| 337 |
+
this.write(zipUtil.getLongBytes(ae.getExternalAttributes()));
|
| 338 |
+
|
| 339 |
+
// relative offset of LFH
|
| 340 |
+
this.write(zipUtil.getLongBytes(fileOffset));
|
| 341 |
+
|
| 342 |
+
// name
|
| 343 |
+
this.write(name);
|
| 344 |
+
|
| 345 |
+
// extra
|
| 346 |
+
this.write(extra);
|
| 347 |
+
|
| 348 |
+
// comment
|
| 349 |
+
this.write(comment);
|
| 350 |
+
};
|
| 351 |
+
|
| 352 |
+
ZipArchiveOutputStream.prototype._writeDataDescriptor = function(ae) {
|
| 353 |
+
// signature
|
| 354 |
+
this.write(zipUtil.getLongBytes(constants.SIG_DD));
|
| 355 |
+
|
| 356 |
+
// crc32 checksum
|
| 357 |
+
this.write(zipUtil.getLongBytes(ae.getCrc()));
|
| 358 |
+
|
| 359 |
+
// sizes
|
| 360 |
+
if (ae.isZip64()) {
|
| 361 |
+
this.write(zipUtil.getEightBytes(ae.getCompressedSize()));
|
| 362 |
+
this.write(zipUtil.getEightBytes(ae.getSize()));
|
| 363 |
+
} else {
|
| 364 |
+
this.write(zipUtil.getLongBytes(ae.getCompressedSize()));
|
| 365 |
+
this.write(zipUtil.getLongBytes(ae.getSize()));
|
| 366 |
+
}
|
| 367 |
+
};
|
| 368 |
+
|
| 369 |
+
ZipArchiveOutputStream.prototype._writeLocalFileHeader = function(ae) {
|
| 370 |
+
var gpb = ae.getGeneralPurposeBit();
|
| 371 |
+
var method = ae.getMethod();
|
| 372 |
+
var name = ae.getName();
|
| 373 |
+
var extra = ae.getLocalFileDataExtra();
|
| 374 |
+
|
| 375 |
+
if (ae.isZip64()) {
|
| 376 |
+
gpb.useDataDescriptor(true);
|
| 377 |
+
ae.setVersionNeededToExtract(constants.MIN_VERSION_ZIP64);
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
if (gpb.usesUTF8ForNames()) {
|
| 381 |
+
name = Buffer.from(name);
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
ae._offsets.file = this.offset;
|
| 385 |
+
|
| 386 |
+
// signature
|
| 387 |
+
this.write(zipUtil.getLongBytes(constants.SIG_LFH));
|
| 388 |
+
|
| 389 |
+
// version to extract and general bit flag
|
| 390 |
+
this.write(zipUtil.getShortBytes(ae.getVersionNeededToExtract()));
|
| 391 |
+
this.write(gpb.encode());
|
| 392 |
+
|
| 393 |
+
// compression method
|
| 394 |
+
this.write(zipUtil.getShortBytes(method));
|
| 395 |
+
|
| 396 |
+
// datetime
|
| 397 |
+
this.write(zipUtil.getLongBytes(ae.getTimeDos()));
|
| 398 |
+
|
| 399 |
+
ae._offsets.data = this.offset;
|
| 400 |
+
|
| 401 |
+
// crc32 checksum and sizes
|
| 402 |
+
if (gpb.usesDataDescriptor()) {
|
| 403 |
+
this.write(constants.LONG_ZERO);
|
| 404 |
+
this.write(constants.LONG_ZERO);
|
| 405 |
+
this.write(constants.LONG_ZERO);
|
| 406 |
+
} else {
|
| 407 |
+
this.write(zipUtil.getLongBytes(ae.getCrc()));
|
| 408 |
+
this.write(zipUtil.getLongBytes(ae.getCompressedSize()));
|
| 409 |
+
this.write(zipUtil.getLongBytes(ae.getSize()));
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
// name length
|
| 413 |
+
this.write(zipUtil.getShortBytes(name.length));
|
| 414 |
+
|
| 415 |
+
// extra length
|
| 416 |
+
this.write(zipUtil.getShortBytes(extra.length));
|
| 417 |
+
|
| 418 |
+
// name
|
| 419 |
+
this.write(name);
|
| 420 |
+
|
| 421 |
+
// extra
|
| 422 |
+
this.write(extra);
|
| 423 |
+
|
| 424 |
+
ae._offsets.contents = this.offset;
|
| 425 |
+
};
|
| 426 |
+
|
| 427 |
+
ZipArchiveOutputStream.prototype.getComment = function(comment) {
|
| 428 |
+
return this._archive.comment !== null ? this._archive.comment : '';
|
| 429 |
+
};
|
| 430 |
+
|
| 431 |
+
ZipArchiveOutputStream.prototype.isZip64 = function() {
|
| 432 |
+
return this._archive.forceZip64 || this._entries.length > constants.ZIP64_MAGIC_SHORT || this._archive.centralLength > constants.ZIP64_MAGIC || this._archive.centralOffset > constants.ZIP64_MAGIC;
|
| 433 |
+
};
|
| 434 |
+
|
| 435 |
+
ZipArchiveOutputStream.prototype.setComment = function(comment) {
|
| 436 |
+
this._archive.comment = comment;
|
| 437 |
+
};
|
node_modules/compress-commons/lib/compress-commons.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* node-compress-commons
|
| 3 |
+
*
|
| 4 |
+
* Copyright (c) 2014 Chris Talkington, contributors.
|
| 5 |
+
* Licensed under the MIT license.
|
| 6 |
+
* https://github.com/archiverjs/node-compress-commons/blob/master/LICENSE-MIT
|
| 7 |
+
*/
|
| 8 |
+
module.exports = {
|
| 9 |
+
ArchiveEntry: require('./archivers/archive-entry'),
|
| 10 |
+
ZipArchiveEntry: require('./archivers/zip/zip-archive-entry'),
|
| 11 |
+
ArchiveOutputStream: require('./archivers/archive-output-stream'),
|
| 12 |
+
ZipArchiveOutputStream: require('./archivers/zip/zip-archive-output-stream')
|
| 13 |
+
};
|
node_modules/compress-commons/lib/util/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* node-compress-commons
|
| 3 |
+
*
|
| 4 |
+
* Copyright (c) 2014 Chris Talkington, contributors.
|
| 5 |
+
* Licensed under the MIT license.
|
| 6 |
+
* https://github.com/archiverjs/node-compress-commons/blob/master/LICENSE-MIT
|
| 7 |
+
*/
|
| 8 |
+
var Stream = require('stream').Stream;
|
| 9 |
+
var PassThrough = require('readable-stream').PassThrough;
|
| 10 |
+
|
| 11 |
+
var util = module.exports = {};
|
| 12 |
+
|
| 13 |
+
util.isStream = function(source) {
|
| 14 |
+
return source instanceof Stream;
|
| 15 |
+
};
|
| 16 |
+
|
| 17 |
+
util.normalizeInputSource = function(source) {
|
| 18 |
+
if (source === null) {
|
| 19 |
+
return Buffer.alloc(0);
|
| 20 |
+
} else if (typeof source === 'string') {
|
| 21 |
+
return Buffer.from(source);
|
| 22 |
+
} else if (util.isStream(source) && !source._readableState) {
|
| 23 |
+
var normalized = new PassThrough();
|
| 24 |
+
source.pipe(normalized);
|
| 25 |
+
|
| 26 |
+
return normalized;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
return source;
|
| 30 |
+
};
|
node_modules/compress-commons/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "compress-commons",
|
| 3 |
+
"version": "5.0.3",
|
| 4 |
+
"description": "a library that defines a common interface for working with archive formats within node",
|
| 5 |
+
"homepage": "https://github.com/archiverjs/node-compress-commons",
|
| 6 |
+
"author": {
|
| 7 |
+
"name": "Chris Talkington",
|
| 8 |
+
"url": "http://christalkington.com/"
|
| 9 |
+
},
|
| 10 |
+
"repository": {
|
| 11 |
+
"type": "git",
|
| 12 |
+
"url": "https://github.com/archiverjs/node-compress-commons.git"
|
| 13 |
+
},
|
| 14 |
+
"bugs": {
|
| 15 |
+
"url": "https://github.com/archiverjs/node-compress-commons/issues"
|
| 16 |
+
},
|
| 17 |
+
"license": "MIT",
|
| 18 |
+
"main": "lib/compress-commons.js",
|
| 19 |
+
"files": [
|
| 20 |
+
"lib"
|
| 21 |
+
],
|
| 22 |
+
"engines": {
|
| 23 |
+
"node": ">= 12.0.0"
|
| 24 |
+
},
|
| 25 |
+
"scripts": {
|
| 26 |
+
"test": "mocha --reporter dot"
|
| 27 |
+
},
|
| 28 |
+
"dependencies": {
|
| 29 |
+
"crc-32": "^1.2.0",
|
| 30 |
+
"crc32-stream": "^5.0.0",
|
| 31 |
+
"normalize-path": "^3.0.0",
|
| 32 |
+
"readable-stream": "^3.6.0"
|
| 33 |
+
},
|
| 34 |
+
"devDependencies": {
|
| 35 |
+
"chai": "4.3.8",
|
| 36 |
+
"mkdirp": "3.0.1",
|
| 37 |
+
"mocha": "9.2.2",
|
| 38 |
+
"rimraf": "3.0.2"
|
| 39 |
+
},
|
| 40 |
+
"keywords": [
|
| 41 |
+
"compress",
|
| 42 |
+
"commons",
|
| 43 |
+
"archive"
|
| 44 |
+
]
|
| 45 |
+
}
|
node_modules/concat-map/.travis.yml
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
language: node_js
|
| 2 |
+
node_js:
|
| 3 |
+
- 0.4
|
| 4 |
+
- 0.6
|
node_modules/concat-map/LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
This software is released under the MIT license:
|
| 2 |
+
|
| 3 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 4 |
+
this software and associated documentation files (the "Software"), to deal in
|
| 5 |
+
the Software without restriction, including without limitation the rights to
|
| 6 |
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
| 7 |
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
| 8 |
+
subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
The above copyright notice and this permission notice shall be included in all
|
| 11 |
+
copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
| 15 |
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 16 |
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
| 17 |
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 18 |
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
node_modules/concat-map/README.markdown
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
concat-map
|
| 2 |
+
==========
|
| 3 |
+
|
| 4 |
+
Concatenative mapdashery.
|
| 5 |
+
|
| 6 |
+
[](http://ci.testling.com/substack/node-concat-map)
|
| 7 |
+
|
| 8 |
+
[](http://travis-ci.org/substack/node-concat-map)
|
| 9 |
+
|
| 10 |
+
example
|
| 11 |
+
=======
|
| 12 |
+
|
| 13 |
+
``` js
|
| 14 |
+
var concatMap = require('concat-map');
|
| 15 |
+
var xs = [ 1, 2, 3, 4, 5, 6 ];
|
| 16 |
+
var ys = concatMap(xs, function (x) {
|
| 17 |
+
return x % 2 ? [ x - 0.1, x, x + 0.1 ] : [];
|
| 18 |
+
});
|
| 19 |
+
console.dir(ys);
|
| 20 |
+
```
|
| 21 |
+
|
| 22 |
+
***
|
| 23 |
+
|
| 24 |
+
```
|
| 25 |
+
[ 0.9, 1, 1.1, 2.9, 3, 3.1, 4.9, 5, 5.1 ]
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
methods
|
| 29 |
+
=======
|
| 30 |
+
|
| 31 |
+
``` js
|
| 32 |
+
var concatMap = require('concat-map')
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
concatMap(xs, fn)
|
| 36 |
+
-----------------
|
| 37 |
+
|
| 38 |
+
Return an array of concatenated elements by calling `fn(x, i)` for each element
|
| 39 |
+
`x` and each index `i` in the array `xs`.
|
| 40 |
+
|
| 41 |
+
When `fn(x, i)` returns an array, its result will be concatenated with the
|
| 42 |
+
result array. If `fn(x, i)` returns anything else, that value will be pushed
|
| 43 |
+
onto the end of the result array.
|
| 44 |
+
|
| 45 |
+
install
|
| 46 |
+
=======
|
| 47 |
+
|
| 48 |
+
With [npm](http://npmjs.org) do:
|
| 49 |
+
|
| 50 |
+
```
|
| 51 |
+
npm install concat-map
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
license
|
| 55 |
+
=======
|
| 56 |
+
|
| 57 |
+
MIT
|
| 58 |
+
|
| 59 |
+
notes
|
| 60 |
+
=====
|
| 61 |
+
|
| 62 |
+
This module was written while sitting high above the ground in a tree.
|
node_modules/concat-map/example/map.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
var concatMap = require('../');
|
| 2 |
+
var xs = [ 1, 2, 3, 4, 5, 6 ];
|
| 3 |
+
var ys = concatMap(xs, function (x) {
|
| 4 |
+
return x % 2 ? [ x - 0.1, x, x + 0.1 ] : [];
|
| 5 |
+
});
|
| 6 |
+
console.dir(ys);
|
node_modules/concat-map/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module.exports = function (xs, fn) {
|
| 2 |
+
var res = [];
|
| 3 |
+
for (var i = 0; i < xs.length; i++) {
|
| 4 |
+
var x = fn(xs[i], i);
|
| 5 |
+
if (isArray(x)) res.push.apply(res, x);
|
| 6 |
+
else res.push(x);
|
| 7 |
+
}
|
| 8 |
+
return res;
|
| 9 |
+
};
|
| 10 |
+
|
| 11 |
+
var isArray = Array.isArray || function (xs) {
|
| 12 |
+
return Object.prototype.toString.call(xs) === '[object Array]';
|
| 13 |
+
};
|
node_modules/concat-map/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name" : "concat-map",
|
| 3 |
+
"description" : "concatenative mapdashery",
|
| 4 |
+
"version" : "0.0.1",
|
| 5 |
+
"repository" : {
|
| 6 |
+
"type" : "git",
|
| 7 |
+
"url" : "git://github.com/substack/node-concat-map.git"
|
| 8 |
+
},
|
| 9 |
+
"main" : "index.js",
|
| 10 |
+
"keywords" : [
|
| 11 |
+
"concat",
|
| 12 |
+
"concatMap",
|
| 13 |
+
"map",
|
| 14 |
+
"functional",
|
| 15 |
+
"higher-order"
|
| 16 |
+
],
|
| 17 |
+
"directories" : {
|
| 18 |
+
"example" : "example",
|
| 19 |
+
"test" : "test"
|
| 20 |
+
},
|
| 21 |
+
"scripts" : {
|
| 22 |
+
"test" : "tape test/*.js"
|
| 23 |
+
},
|
| 24 |
+
"devDependencies" : {
|
| 25 |
+
"tape" : "~2.4.0"
|
| 26 |
+
},
|
| 27 |
+
"license" : "MIT",
|
| 28 |
+
"author" : {
|
| 29 |
+
"name" : "James Halliday",
|
| 30 |
+
"email" : "mail@substack.net",
|
| 31 |
+
"url" : "http://substack.net"
|
| 32 |
+
},
|
| 33 |
+
"testling" : {
|
| 34 |
+
"files" : "test/*.js",
|
| 35 |
+
"browsers" : {
|
| 36 |
+
"ie" : [ 6, 7, 8, 9 ],
|
| 37 |
+
"ff" : [ 3.5, 10, 15.0 ],
|
| 38 |
+
"chrome" : [ 10, 22 ],
|
| 39 |
+
"safari" : [ 5.1 ],
|
| 40 |
+
"opera" : [ 12 ]
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
}
|
node_modules/concat-map/test/map.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
var concatMap = require('../');
|
| 2 |
+
var test = require('tape');
|
| 3 |
+
|
| 4 |
+
test('empty or not', function (t) {
|
| 5 |
+
var xs = [ 1, 2, 3, 4, 5, 6 ];
|
| 6 |
+
var ixes = [];
|
| 7 |
+
var ys = concatMap(xs, function (x, ix) {
|
| 8 |
+
ixes.push(ix);
|
| 9 |
+
return x % 2 ? [ x - 0.1, x, x + 0.1 ] : [];
|
| 10 |
+
});
|
| 11 |
+
t.same(ys, [ 0.9, 1, 1.1, 2.9, 3, 3.1, 4.9, 5, 5.1 ]);
|
| 12 |
+
t.same(ixes, [ 0, 1, 2, 3, 4, 5 ]);
|
| 13 |
+
t.end();
|
| 14 |
+
});
|
| 15 |
+
|
| 16 |
+
test('always something', function (t) {
|
| 17 |
+
var xs = [ 'a', 'b', 'c', 'd' ];
|
| 18 |
+
var ys = concatMap(xs, function (x) {
|
| 19 |
+
return x === 'b' ? [ 'B', 'B', 'B' ] : [ x ];
|
| 20 |
+
});
|
| 21 |
+
t.same(ys, [ 'a', 'B', 'B', 'B', 'c', 'd' ]);
|
| 22 |
+
t.end();
|
| 23 |
+
});
|
| 24 |
+
|
| 25 |
+
test('scalars', function (t) {
|
| 26 |
+
var xs = [ 'a', 'b', 'c', 'd' ];
|
| 27 |
+
var ys = concatMap(xs, function (x) {
|
| 28 |
+
return x === 'b' ? [ 'B', 'B', 'B' ] : x;
|
| 29 |
+
});
|
| 30 |
+
t.same(ys, [ 'a', 'B', 'B', 'B', 'c', 'd' ]);
|
| 31 |
+
t.end();
|
| 32 |
+
});
|
| 33 |
+
|
| 34 |
+
test('undefs', function (t) {
|
| 35 |
+
var xs = [ 'a', 'b', 'c', 'd' ];
|
| 36 |
+
var ys = concatMap(xs, function () {});
|
| 37 |
+
t.same(ys, [ undefined, undefined, undefined, undefined ]);
|
| 38 |
+
t.end();
|
| 39 |
+
});
|
node_modules/concat-stream/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2013 Max Ogden
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge,
|
| 6 |
+
to any person obtaining a copy of this software and
|
| 7 |
+
associated documentation files (the "Software"), to
|
| 8 |
+
deal in the Software without restriction, including
|
| 9 |
+
without limitation the rights to use, copy, modify,
|
| 10 |
+
merge, publish, distribute, sublicense, and/or sell
|
| 11 |
+
copies of the Software, and to permit persons to whom
|
| 12 |
+
the Software is furnished to do so,
|
| 13 |
+
subject to the following conditions:
|
| 14 |
+
|
| 15 |
+
The above copyright notice and this permission notice
|
| 16 |
+
shall be included in all copies or substantial portions of the Software.
|
| 17 |
+
|
| 18 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 19 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
| 20 |
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
| 21 |
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
| 22 |
+
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRAC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Writable = require('readable-stream').Writable
|
| 2 |
+
var inherits = require('inherits')
|
| 3 |
+
var bufferFrom = require('buffer-from')
|
| 4 |
+
|
| 5 |
+
if (typeof Uint8Array === 'undefined') {
|
| 6 |
+
var U8 = require('typedarray').Uint8Array
|
| 7 |
+
} else {
|
| 8 |
+
var U8 = Uint8Array
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
function ConcatStream(opts, cb) {
|
| 12 |
+
if (!(this instanceof ConcatStream)) return new ConcatStream(opts, cb)
|
| 13 |
+
|
| 14 |
+
if (typeof opts === 'function') {
|
| 15 |
+
cb = opts
|
| 16 |
+
opts = {}
|
| 17 |
+
}
|
| 18 |
+
if (!opts) opts = {}
|
| 19 |
+
|
| 20 |
+
var encoding = opts.encoding
|
| 21 |
+
var shouldInferEncoding = false
|
| 22 |
+
|
| 23 |
+
if (!encoding) {
|
| 24 |
+
shouldInferEncoding = true
|
| 25 |
+
} else {
|
| 26 |
+
encoding = String(encoding).toLowerCase()
|
| 27 |
+
if (encoding === 'u8' || encoding === 'uint8') {
|
| 28 |
+
encoding = 'uint8array'
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
Writable.call(this, { objectMode: true })
|
| 33 |
+
|
| 34 |
+
this.encoding = encoding
|
| 35 |
+
this.shouldInferEncoding = shouldInferEncoding
|
| 36 |
+
|
| 37 |
+
if (cb) this.on('finish', function () { cb(this.getBody()) })
|
| 38 |
+
this.body = []
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
module.exports = ConcatStream
|
| 42 |
+
inherits(ConcatStream, Writable)
|
| 43 |
+
|
| 44 |
+
ConcatStream.prototype._write = function(chunk, enc, next) {
|
| 45 |
+
this.body.push(chunk)
|
| 46 |
+
next()
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
ConcatStream.prototype.inferEncoding = function (buff) {
|
| 50 |
+
var firstBuffer = buff === undefined ? this.body[0] : buff;
|
| 51 |
+
if (Buffer.isBuffer(firstBuffer)) return 'buffer'
|
| 52 |
+
if (typeof Uint8Array !== 'undefined' && firstBuffer instanceof Uint8Array) return 'uint8array'
|
| 53 |
+
if (Array.isArray(firstBuffer)) return 'array'
|
| 54 |
+
if (typeof firstBuffer === 'string') return 'string'
|
| 55 |
+
if (Object.prototype.toString.call(firstBuffer) === "[object Object]") return 'object'
|
| 56 |
+
return 'buffer'
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
ConcatStream.prototype.getBody = function () {
|
| 60 |
+
if (!this.encoding && this.body.length === 0) return []
|
| 61 |
+
if (this.shouldInferEncoding) this.encoding = this.inferEncoding()
|
| 62 |
+
if (this.encoding === 'array') return arrayConcat(this.body)
|
| 63 |
+
if (this.encoding === 'string') return stringConcat(this.body)
|
| 64 |
+
if (this.encoding === 'buffer') return bufferConcat(this.body)
|
| 65 |
+
if (this.encoding === 'uint8array') return u8Concat(this.body)
|
| 66 |
+
return this.body
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
var isArray = Array.isArray || function (arr) {
|
| 70 |
+
return Object.prototype.toString.call(arr) == '[object Array]'
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
function isArrayish (arr) {
|
| 74 |
+
return /Array\]$/.test(Object.prototype.toString.call(arr))
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
function isBufferish (p) {
|
| 78 |
+
return typeof p === 'string' || isArrayish(p) || (p && typeof p.subarray === 'function')
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
function stringConcat (parts) {
|
| 82 |
+
var strings = []
|
| 83 |
+
var needsToString = false
|
| 84 |
+
for (var i = 0; i < parts.length; i++) {
|
| 85 |
+
var p = parts[i]
|
| 86 |
+
if (typeof p === 'string') {
|
| 87 |
+
strings.push(p)
|
| 88 |
+
} else if (Buffer.isBuffer(p)) {
|
| 89 |
+
strings.push(p)
|
| 90 |
+
} else if (isBufferish(p)) {
|
| 91 |
+
strings.push(bufferFrom(p))
|
| 92 |
+
} else {
|
| 93 |
+
strings.push(bufferFrom(String(p)))
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
if (Buffer.isBuffer(parts[0])) {
|
| 97 |
+
strings = Buffer.concat(strings)
|
| 98 |
+
strings = strings.toString('utf8')
|
| 99 |
+
} else {
|
| 100 |
+
strings = strings.join('')
|
| 101 |
+
}
|
| 102 |
+
return strings
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
function bufferConcat (parts) {
|
| 106 |
+
var bufs = []
|
| 107 |
+
for (var i = 0; i < parts.length; i++) {
|
| 108 |
+
var p = parts[i]
|
| 109 |
+
if (Buffer.isBuffer(p)) {
|
| 110 |
+
bufs.push(p)
|
| 111 |
+
} else if (isBufferish(p)) {
|
| 112 |
+
bufs.push(bufferFrom(p))
|
| 113 |
+
} else {
|
| 114 |
+
bufs.push(bufferFrom(String(p)))
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
return Buffer.concat(bufs)
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
function arrayConcat (parts) {
|
| 121 |
+
var res = []
|
| 122 |
+
for (var i = 0; i < parts.length; i++) {
|
| 123 |
+
res.push.apply(res, parts[i])
|
| 124 |
+
}
|
| 125 |
+
return res
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
function u8Concat (parts) {
|
| 129 |
+
var len = 0
|
| 130 |
+
for (var i = 0; i < parts.length; i++) {
|
| 131 |
+
if (typeof parts[i] === 'string') {
|
| 132 |
+
parts[i] = bufferFrom(parts[i])
|
| 133 |
+
}
|
| 134 |
+
len += parts[i].length
|
| 135 |
+
}
|
| 136 |
+
var u8 = new U8(len)
|
| 137 |
+
for (var i = 0, offset = 0; i < parts.length; i++) {
|
| 138 |
+
var part = parts[i]
|
| 139 |
+
for (var j = 0; j < part.length; j++) {
|
| 140 |
+
u8[offset++] = part[j]
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
return u8
|
| 144 |
+
}
|
node_modules/concat-stream/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "concat-stream",
|
| 3 |
+
"version": "2.0.0",
|
| 4 |
+
"description": "writable stream that concatenates strings or binary data and calls a callback with the result",
|
| 5 |
+
"tags": [
|
| 6 |
+
"stream",
|
| 7 |
+
"simple",
|
| 8 |
+
"util",
|
| 9 |
+
"utility"
|
| 10 |
+
],
|
| 11 |
+
"author": "Max Ogden <max@maxogden.com>",
|
| 12 |
+
"repository": {
|
| 13 |
+
"type": "git",
|
| 14 |
+
"url": "http://github.com/maxogden/concat-stream.git"
|
| 15 |
+
},
|
| 16 |
+
"bugs": {
|
| 17 |
+
"url": "http://github.com/maxogden/concat-stream/issues"
|
| 18 |
+
},
|
| 19 |
+
"engines": [
|
| 20 |
+
"node >= 6.0"
|
| 21 |
+
],
|
| 22 |
+
"main": "index.js",
|
| 23 |
+
"files": [
|
| 24 |
+
"index.js"
|
| 25 |
+
],
|
| 26 |
+
"scripts": {
|
| 27 |
+
"test": "tape test/*.js test/server/*.js"
|
| 28 |
+
},
|
| 29 |
+
"license": "MIT",
|
| 30 |
+
"dependencies": {
|
| 31 |
+
"buffer-from": "^1.0.0",
|
| 32 |
+
"inherits": "^2.0.3",
|
| 33 |
+
"readable-stream": "^3.0.2",
|
| 34 |
+
"typedarray": "^0.0.6"
|
| 35 |
+
},
|
| 36 |
+
"devDependencies": {
|
| 37 |
+
"tape": "^4.6.3"
|
| 38 |
+
},
|
| 39 |
+
"testling": {
|
| 40 |
+
"files": "test/*.js",
|
| 41 |
+
"browsers": [
|
| 42 |
+
"ie/8..latest",
|
| 43 |
+
"firefox/17..latest",
|
| 44 |
+
"firefox/nightly",
|
| 45 |
+
"chrome/22..latest",
|
| 46 |
+
"chrome/canary",
|
| 47 |
+
"opera/12..latest",
|
| 48 |
+
"opera/next",
|
| 49 |
+
"safari/5.1..latest",
|
| 50 |
+
"ipad/6.0..latest",
|
| 51 |
+
"iphone/6.0..latest",
|
| 52 |
+
"android-browser/4.2..latest"
|
| 53 |
+
]
|
| 54 |
+
}
|
| 55 |
+
}
|
node_modules/concat-stream/readme.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# concat-stream
|
| 2 |
+
|
| 3 |
+
Writable stream that concatenates all the data from a stream and calls a callback with the result. Use this when you want to collect all the data from a stream into a single buffer.
|
| 4 |
+
|
| 5 |
+
[](https://travis-ci.org/maxogden/concat-stream)
|
| 6 |
+
|
| 7 |
+
[](https://nodei.co/npm/concat-stream/)
|
| 8 |
+
|
| 9 |
+
### description
|
| 10 |
+
|
| 11 |
+
Streams emit many buffers. If you want to collect all of the buffers, and when the stream ends concatenate all of the buffers together and receive a single buffer then this is the module for you.
|
| 12 |
+
|
| 13 |
+
Only use this if you know you can fit all of the output of your stream into a single Buffer (e.g. in RAM).
|
| 14 |
+
|
| 15 |
+
There are also `objectMode` streams that emit things other than Buffers, and you can concatenate these too. See below for details.
|
| 16 |
+
|
| 17 |
+
## Related
|
| 18 |
+
|
| 19 |
+
`concat-stream` is part of the [mississippi stream utility collection](https://github.com/maxogden/mississippi) which includes more useful stream modules similar to this one.
|
| 20 |
+
|
| 21 |
+
### examples
|
| 22 |
+
|
| 23 |
+
#### Buffers
|
| 24 |
+
|
| 25 |
+
```js
|
| 26 |
+
var fs = require('fs')
|
| 27 |
+
var concat = require('concat-stream')
|
| 28 |
+
|
| 29 |
+
var readStream = fs.createReadStream('cat.png')
|
| 30 |
+
var concatStream = concat(gotPicture)
|
| 31 |
+
|
| 32 |
+
readStream.on('error', handleError)
|
| 33 |
+
readStream.pipe(concatStream)
|
| 34 |
+
|
| 35 |
+
function gotPicture(imageBuffer) {
|
| 36 |
+
// imageBuffer is all of `cat.png` as a node.js Buffer
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
function handleError(err) {
|
| 40 |
+
// handle your error appropriately here, e.g.:
|
| 41 |
+
console.error(err) // print the error to STDERR
|
| 42 |
+
process.exit(1) // exit program with non-zero exit code
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
#### Arrays
|
| 48 |
+
|
| 49 |
+
```js
|
| 50 |
+
var write = concat(function(data) {})
|
| 51 |
+
write.write([1,2,3])
|
| 52 |
+
write.write([4,5,6])
|
| 53 |
+
write.end()
|
| 54 |
+
// data will be [1,2,3,4,5,6] in the above callback
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
#### Uint8Arrays
|
| 58 |
+
|
| 59 |
+
```js
|
| 60 |
+
var write = concat(function(data) {})
|
| 61 |
+
var a = new Uint8Array(3)
|
| 62 |
+
a[0] = 97; a[1] = 98; a[2] = 99
|
| 63 |
+
write.write(a)
|
| 64 |
+
write.write('!')
|
| 65 |
+
write.end(Buffer.from('!!1'))
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
See `test/` for more examples
|
| 69 |
+
|
| 70 |
+
# methods
|
| 71 |
+
|
| 72 |
+
```js
|
| 73 |
+
var concat = require('concat-stream')
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
## var writable = concat(opts={}, cb)
|
| 77 |
+
|
| 78 |
+
Return a `writable` stream that will fire `cb(data)` with all of the data that
|
| 79 |
+
was written to the stream. Data can be written to `writable` as strings,
|
| 80 |
+
Buffers, arrays of byte integers, and Uint8Arrays.
|
| 81 |
+
|
| 82 |
+
By default `concat-stream` will give you back the same data type as the type of the first buffer written to the stream. Use `opts.encoding` to set what format `data` should be returned as, e.g. if you if you don't want to rely on the built-in type checking or for some other reason.
|
| 83 |
+
|
| 84 |
+
* `string` - get a string
|
| 85 |
+
* `buffer` - get back a Buffer
|
| 86 |
+
* `array` - get an array of byte integers
|
| 87 |
+
* `uint8array`, `u8`, `uint8` - get back a Uint8Array
|
| 88 |
+
* `object`, get back an array of Objects
|
| 89 |
+
|
| 90 |
+
If you don't specify an encoding, and the types can't be inferred (e.g. you write things that aren't in the list above), it will try to convert concat them into a `Buffer`.
|
| 91 |
+
|
| 92 |
+
If nothing is written to `writable` then `data` will be an empty array `[]`.
|
| 93 |
+
|
| 94 |
+
# error handling
|
| 95 |
+
|
| 96 |
+
`concat-stream` does not handle errors for you, so you must handle errors on whatever streams you pipe into `concat-stream`. This is a general rule when programming with node.js streams: always handle errors on each and every stream. Since `concat-stream` is not itself a stream it does not emit errors.
|
| 97 |
+
|
| 98 |
+
We recommend using [`end-of-stream`](https://npmjs.org/end-of-stream) or [`pump`](https://npmjs.org/pump) for writing error tolerant stream code.
|
| 99 |
+
|
| 100 |
+
# license
|
| 101 |
+
|
| 102 |
+
MIT LICENSE
|
node_modules/content-disposition/HISTORY.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
0.5.4 / 2021-12-10
|
| 2 |
+
==================
|
| 3 |
+
|
| 4 |
+
* deps: safe-buffer@5.2.1
|
| 5 |
+
|
| 6 |
+
0.5.3 / 2018-12-17
|
| 7 |
+
==================
|
| 8 |
+
|
| 9 |
+
* Use `safe-buffer` for improved Buffer API
|
| 10 |
+
|
| 11 |
+
0.5.2 / 2016-12-08
|
| 12 |
+
==================
|
| 13 |
+
|
| 14 |
+
* Fix `parse` to accept any linear whitespace character
|
| 15 |
+
|
| 16 |
+
0.5.1 / 2016-01-17
|
| 17 |
+
==================
|
| 18 |
+
|
| 19 |
+
* perf: enable strict mode
|
| 20 |
+
|
| 21 |
+
0.5.0 / 2014-10-11
|
| 22 |
+
==================
|
| 23 |
+
|
| 24 |
+
* Add `parse` function
|
| 25 |
+
|
| 26 |
+
0.4.0 / 2014-09-21
|
| 27 |
+
==================
|
| 28 |
+
|
| 29 |
+
* Expand non-Unicode `filename` to the full ISO-8859-1 charset
|
| 30 |
+
|
| 31 |
+
0.3.0 / 2014-09-20
|
| 32 |
+
==================
|
| 33 |
+
|
| 34 |
+
* Add `fallback` option
|
| 35 |
+
* Add `type` option
|
| 36 |
+
|
| 37 |
+
0.2.0 / 2014-09-19
|
| 38 |
+
==================
|
| 39 |
+
|
| 40 |
+
* Reduce ambiguity of file names with hex escape in buggy browsers
|
| 41 |
+
|
| 42 |
+
0.1.2 / 2014-09-19
|
| 43 |
+
==================
|
| 44 |
+
|
| 45 |
+
* Fix periodic invalid Unicode filename header
|
| 46 |
+
|
| 47 |
+
0.1.1 / 2014-09-19
|
| 48 |
+
==================
|
| 49 |
+
|
| 50 |
+
* Fix invalid characters appearing in `filename*` parameter
|
| 51 |
+
|
| 52 |
+
0.1.0 / 2014-09-18
|
| 53 |
+
==================
|
| 54 |
+
|
| 55 |
+
* Make the `filename` argument optional
|
| 56 |
+
|
| 57 |
+
0.0.0 / 2014-09-18
|
| 58 |
+
==================
|
| 59 |
+
|
| 60 |
+
* Initial release
|
node_modules/content-disposition/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
(The MIT License)
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2014-2017 Douglas Christopher Wilson
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining
|
| 6 |
+
a copy of this software and associated documentation files (the
|
| 7 |
+
'Software'), to deal in the Software without restriction, including
|
| 8 |
+
without limitation the rights to use, copy, modify, merge, publish,
|
| 9 |
+
distribute, sublicense, and/or sell copies of the Software, and to
|
| 10 |
+
permit persons to whom the Software is furnished to do so, subject to
|
| 11 |
+
the following conditions:
|
| 12 |
+
|
| 13 |
+
The above copyright notice and this permission notice shall be
|
| 14 |
+
included in all copies or substantial portions of the Software.
|
| 15 |
+
|
| 16 |
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
| 17 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 18 |
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
| 19 |
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
| 20 |
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
| 21 |
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
| 22 |
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
node_modules/content-disposition/README.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# content-disposition
|
| 2 |
+
|
| 3 |
+
[![NPM Version][npm-image]][npm-url]
|
| 4 |
+
[![NPM Downloads][downloads-image]][downloads-url]
|
| 5 |
+
[![Node.js Version][node-version-image]][node-version-url]
|
| 6 |
+
[![Build Status][github-actions-ci-image]][github-actions-ci-url]
|
| 7 |
+
[![Test Coverage][coveralls-image]][coveralls-url]
|
| 8 |
+
|
| 9 |
+
Create and parse HTTP `Content-Disposition` header
|
| 10 |
+
|
| 11 |
+
## Installation
|
| 12 |
+
|
| 13 |
+
```sh
|
| 14 |
+
$ npm install content-disposition
|
| 15 |
+
```
|
| 16 |
+
|
| 17 |
+
## API
|
| 18 |
+
|
| 19 |
+
```js
|
| 20 |
+
var contentDisposition = require('content-disposition')
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
### contentDisposition(filename, options)
|
| 24 |
+
|
| 25 |
+
Create an attachment `Content-Disposition` header value using the given file name,
|
| 26 |
+
if supplied. The `filename` is optional and if no file name is desired, but you
|
| 27 |
+
want to specify `options`, set `filename` to `undefined`.
|
| 28 |
+
|
| 29 |
+
```js
|
| 30 |
+
res.setHeader('Content-Disposition', contentDisposition('∫ maths.pdf'))
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
**note** HTTP headers are of the ISO-8859-1 character set. If you are writing this
|
| 34 |
+
header through a means different from `setHeader` in Node.js, you'll want to specify
|
| 35 |
+
the `'binary'` encoding in Node.js.
|
| 36 |
+
|
| 37 |
+
#### Options
|
| 38 |
+
|
| 39 |
+
`contentDisposition` accepts these properties in the options object.
|
| 40 |
+
|
| 41 |
+
##### fallback
|
| 42 |
+
|
| 43 |
+
If the `filename` option is outside ISO-8859-1, then the file name is actually
|
| 44 |
+
stored in a supplemental field for clients that support Unicode file names and
|
| 45 |
+
a ISO-8859-1 version of the file name is automatically generated.
|
| 46 |
+
|
| 47 |
+
This specifies the ISO-8859-1 file name to override the automatic generation or
|
| 48 |
+
disables the generation all together, defaults to `true`.
|
| 49 |
+
|
| 50 |
+
- A string will specify the ISO-8859-1 file name to use in place of automatic
|
| 51 |
+
generation.
|
| 52 |
+
- `false` will disable including a ISO-8859-1 file name and only include the
|
| 53 |
+
Unicode version (unless the file name is already ISO-8859-1).
|
| 54 |
+
- `true` will enable automatic generation if the file name is outside ISO-8859-1.
|
| 55 |
+
|
| 56 |
+
If the `filename` option is ISO-8859-1 and this option is specified and has a
|
| 57 |
+
different value, then the `filename` option is encoded in the extended field
|
| 58 |
+
and this set as the fallback field, even though they are both ISO-8859-1.
|
| 59 |
+
|
| 60 |
+
##### type
|
| 61 |
+
|
| 62 |
+
Specifies the disposition type, defaults to `"attachment"`. This can also be
|
| 63 |
+
`"inline"`, or any other value (all values except inline are treated like
|
| 64 |
+
`attachment`, but can convey additional information if both parties agree to
|
| 65 |
+
it). The type is normalized to lower-case.
|
| 66 |
+
|
| 67 |
+
### contentDisposition.parse(string)
|
| 68 |
+
|
| 69 |
+
```js
|
| 70 |
+
var disposition = contentDisposition.parse('attachment; filename="EURO rates.txt"; filename*=UTF-8\'\'%e2%82%ac%20rates.txt')
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
Parse a `Content-Disposition` header string. This automatically handles extended
|
| 74 |
+
("Unicode") parameters by decoding them and providing them under the standard
|
| 75 |
+
parameter name. This will return an object with the following properties (examples
|
| 76 |
+
are shown for the string `'attachment; filename="EURO rates.txt"; filename*=UTF-8\'\'%e2%82%ac%20rates.txt'`):
|
| 77 |
+
|
| 78 |
+
- `type`: The disposition type (always lower case). Example: `'attachment'`
|
| 79 |
+
|
| 80 |
+
- `parameters`: An object of the parameters in the disposition (name of parameter
|
| 81 |
+
always lower case and extended versions replace non-extended versions). Example:
|
| 82 |
+
`{filename: "€ rates.txt"}`
|
| 83 |
+
|
| 84 |
+
## Examples
|
| 85 |
+
|
| 86 |
+
### Send a file for download
|
| 87 |
+
|
| 88 |
+
```js
|
| 89 |
+
var contentDisposition = require('content-disposition')
|
| 90 |
+
var destroy = require('destroy')
|
| 91 |
+
var fs = require('fs')
|
| 92 |
+
var http = require('http')
|
| 93 |
+
var onFinished = require('on-finished')
|
| 94 |
+
|
| 95 |
+
var filePath = '/path/to/public/plans.pdf'
|
| 96 |
+
|
| 97 |
+
http.createServer(function onRequest (req, res) {
|
| 98 |
+
// set headers
|
| 99 |
+
res.setHeader('Content-Type', 'application/pdf')
|
| 100 |
+
res.setHeader('Content-Disposition', contentDisposition(filePath))
|
| 101 |
+
|
| 102 |
+
// send file
|
| 103 |
+
var stream = fs.createReadStream(filePath)
|
| 104 |
+
stream.pipe(res)
|
| 105 |
+
onFinished(res, function () {
|
| 106 |
+
destroy(stream)
|
| 107 |
+
})
|
| 108 |
+
})
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
## Testing
|
| 112 |
+
|
| 113 |
+
```sh
|
| 114 |
+
$ npm test
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
## References
|
| 118 |
+
|
| 119 |
+
- [RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1][rfc-2616]
|
| 120 |
+
- [RFC 5987: Character Set and Language Encoding for Hypertext Transfer Protocol (HTTP) Header Field Parameters][rfc-5987]
|
| 121 |
+
- [RFC 6266: Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP)][rfc-6266]
|
| 122 |
+
- [Test Cases for HTTP Content-Disposition header field (RFC 6266) and the Encodings defined in RFCs 2047, 2231 and 5987][tc-2231]
|
| 123 |
+
|
| 124 |
+
[rfc-2616]: https://tools.ietf.org/html/rfc2616
|
| 125 |
+
[rfc-5987]: https://tools.ietf.org/html/rfc5987
|
| 126 |
+
[rfc-6266]: https://tools.ietf.org/html/rfc6266
|
| 127 |
+
[tc-2231]: http://greenbytes.de/tech/tc2231/
|
| 128 |
+
|
| 129 |
+
## License
|
| 130 |
+
|
| 131 |
+
[MIT](LICENSE)
|
| 132 |
+
|
| 133 |
+
[npm-image]: https://img.shields.io/npm/v/content-disposition.svg
|
| 134 |
+
[npm-url]: https://npmjs.org/package/content-disposition
|
| 135 |
+
[node-version-image]: https://img.shields.io/node/v/content-disposition.svg
|
| 136 |
+
[node-version-url]: https://nodejs.org/en/download
|
| 137 |
+
[coveralls-image]: https://img.shields.io/coveralls/jshttp/content-disposition.svg
|
| 138 |
+
[coveralls-url]: https://coveralls.io/r/jshttp/content-disposition?branch=master
|
| 139 |
+
[downloads-image]: https://img.shields.io/npm/dm/content-disposition.svg
|
| 140 |
+
[downloads-url]: https://npmjs.org/package/content-disposition
|
| 141 |
+
[github-actions-ci-image]: https://img.shields.io/github/workflow/status/jshttp/content-disposition/ci/master?label=ci
|
| 142 |
+
[github-actions-ci-url]: https://github.com/jshttp/content-disposition?query=workflow%3Aci
|
node_modules/content-disposition/index.js
ADDED
|
@@ -0,0 +1,458 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*!
|
| 2 |
+
* content-disposition
|
| 3 |
+
* Copyright(c) 2014-2017 Douglas Christopher Wilson
|
| 4 |
+
* MIT Licensed
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
'use strict'
|
| 8 |
+
|
| 9 |
+
/**
|
| 10 |
+
* Module exports.
|
| 11 |
+
* @public
|
| 12 |
+
*/
|
| 13 |
+
|
| 14 |
+
module.exports = contentDisposition
|
| 15 |
+
module.exports.parse = parse
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* Module dependencies.
|
| 19 |
+
* @private
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
var basename = require('path').basename
|
| 23 |
+
var Buffer = require('safe-buffer').Buffer
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* RegExp to match non attr-char, *after* encodeURIComponent (i.e. not including "%")
|
| 27 |
+
* @private
|
| 28 |
+
*/
|
| 29 |
+
|
| 30 |
+
var ENCODE_URL_ATTR_CHAR_REGEXP = /[\x00-\x20"'()*,/:;<=>?@[\\\]{}\x7f]/g // eslint-disable-line no-control-regex
|
| 31 |
+
|
| 32 |
+
/**
|
| 33 |
+
* RegExp to match percent encoding escape.
|
| 34 |
+
* @private
|
| 35 |
+
*/
|
| 36 |
+
|
| 37 |
+
var HEX_ESCAPE_REGEXP = /%[0-9A-Fa-f]{2}/
|
| 38 |
+
var HEX_ESCAPE_REPLACE_REGEXP = /%([0-9A-Fa-f]{2})/g
|
| 39 |
+
|
| 40 |
+
/**
|
| 41 |
+
* RegExp to match non-latin1 characters.
|
| 42 |
+
* @private
|
| 43 |
+
*/
|
| 44 |
+
|
| 45 |
+
var NON_LATIN1_REGEXP = /[^\x20-\x7e\xa0-\xff]/g
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* RegExp to match quoted-pair in RFC 2616
|
| 49 |
+
*
|
| 50 |
+
* quoted-pair = "\" CHAR
|
| 51 |
+
* CHAR = <any US-ASCII character (octets 0 - 127)>
|
| 52 |
+
* @private
|
| 53 |
+
*/
|
| 54 |
+
|
| 55 |
+
var QESC_REGEXP = /\\([\u0000-\u007f])/g // eslint-disable-line no-control-regex
|
| 56 |
+
|
| 57 |
+
/**
|
| 58 |
+
* RegExp to match chars that must be quoted-pair in RFC 2616
|
| 59 |
+
* @private
|
| 60 |
+
*/
|
| 61 |
+
|
| 62 |
+
var QUOTE_REGEXP = /([\\"])/g
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* RegExp for various RFC 2616 grammar
|
| 66 |
+
*
|
| 67 |
+
* parameter = token "=" ( token | quoted-string )
|
| 68 |
+
* token = 1*<any CHAR except CTLs or separators>
|
| 69 |
+
* separators = "(" | ")" | "<" | ">" | "@"
|
| 70 |
+
* | "," | ";" | ":" | "\" | <">
|
| 71 |
+
* | "/" | "[" | "]" | "?" | "="
|
| 72 |
+
* | "{" | "}" | SP | HT
|
| 73 |
+
* quoted-string = ( <"> *(qdtext | quoted-pair ) <"> )
|
| 74 |
+
* qdtext = <any TEXT except <">>
|
| 75 |
+
* quoted-pair = "\" CHAR
|
| 76 |
+
* CHAR = <any US-ASCII character (octets 0 - 127)>
|
| 77 |
+
* TEXT = <any OCTET except CTLs, but including LWS>
|
| 78 |
+
* LWS = [CRLF] 1*( SP | HT )
|
| 79 |
+
* CRLF = CR LF
|
| 80 |
+
* CR = <US-ASCII CR, carriage return (13)>
|
| 81 |
+
* LF = <US-ASCII LF, linefeed (10)>
|
| 82 |
+
* SP = <US-ASCII SP, space (32)>
|
| 83 |
+
* HT = <US-ASCII HT, horizontal-tab (9)>
|
| 84 |
+
* CTL = <any US-ASCII control character (octets 0 - 31) and DEL (127)>
|
| 85 |
+
* OCTET = <any 8-bit sequence of data>
|
| 86 |
+
* @private
|
| 87 |
+
*/
|
| 88 |
+
|
| 89 |
+
var PARAM_REGEXP = /;[\x09\x20]*([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*=[\x09\x20]*("(?:[\x20!\x23-\x5b\x5d-\x7e\x80-\xff]|\\[\x20-\x7e])*"|[!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*/g // eslint-disable-line no-control-regex
|
| 90 |
+
var TEXT_REGEXP = /^[\x20-\x7e\x80-\xff]+$/
|
| 91 |
+
var TOKEN_REGEXP = /^[!#$%&'*+.0-9A-Z^_`a-z|~-]+$/
|
| 92 |
+
|
| 93 |
+
/**
|
| 94 |
+
* RegExp for various RFC 5987 grammar
|
| 95 |
+
*
|
| 96 |
+
* ext-value = charset "'" [ language ] "'" value-chars
|
| 97 |
+
* charset = "UTF-8" / "ISO-8859-1" / mime-charset
|
| 98 |
+
* mime-charset = 1*mime-charsetc
|
| 99 |
+
* mime-charsetc = ALPHA / DIGIT
|
| 100 |
+
* / "!" / "#" / "$" / "%" / "&"
|
| 101 |
+
* / "+" / "-" / "^" / "_" / "`"
|
| 102 |
+
* / "{" / "}" / "~"
|
| 103 |
+
* language = ( 2*3ALPHA [ extlang ] )
|
| 104 |
+
* / 4ALPHA
|
| 105 |
+
* / 5*8ALPHA
|
| 106 |
+
* extlang = *3( "-" 3ALPHA )
|
| 107 |
+
* value-chars = *( pct-encoded / attr-char )
|
| 108 |
+
* pct-encoded = "%" HEXDIG HEXDIG
|
| 109 |
+
* attr-char = ALPHA / DIGIT
|
| 110 |
+
* / "!" / "#" / "$" / "&" / "+" / "-" / "."
|
| 111 |
+
* / "^" / "_" / "`" / "|" / "~"
|
| 112 |
+
* @private
|
| 113 |
+
*/
|
| 114 |
+
|
| 115 |
+
var EXT_VALUE_REGEXP = /^([A-Za-z0-9!#$%&+\-^_`{}~]+)'(?:[A-Za-z]{2,3}(?:-[A-Za-z]{3}){0,3}|[A-Za-z]{4,8}|)'((?:%[0-9A-Fa-f]{2}|[A-Za-z0-9!#$&+.^_`|~-])+)$/
|
| 116 |
+
|
| 117 |
+
/**
|
| 118 |
+
* RegExp for various RFC 6266 grammar
|
| 119 |
+
*
|
| 120 |
+
* disposition-type = "inline" | "attachment" | disp-ext-type
|
| 121 |
+
* disp-ext-type = token
|
| 122 |
+
* disposition-parm = filename-parm | disp-ext-parm
|
| 123 |
+
* filename-parm = "filename" "=" value
|
| 124 |
+
* | "filename*" "=" ext-value
|
| 125 |
+
* disp-ext-parm = token "=" value
|
| 126 |
+
* | ext-token "=" ext-value
|
| 127 |
+
* ext-token = <the characters in token, followed by "*">
|
| 128 |
+
* @private
|
| 129 |
+
*/
|
| 130 |
+
|
| 131 |
+
var DISPOSITION_TYPE_REGEXP = /^([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*(?:$|;)/ // eslint-disable-line no-control-regex
|
| 132 |
+
|
| 133 |
+
/**
|
| 134 |
+
* Create an attachment Content-Disposition header.
|
| 135 |
+
*
|
| 136 |
+
* @param {string} [filename]
|
| 137 |
+
* @param {object} [options]
|
| 138 |
+
* @param {string} [options.type=attachment]
|
| 139 |
+
* @param {string|boolean} [options.fallback=true]
|
| 140 |
+
* @return {string}
|
| 141 |
+
* @public
|
| 142 |
+
*/
|
| 143 |
+
|
| 144 |
+
function contentDisposition (filename, options) {
|
| 145 |
+
var opts = options || {}
|
| 146 |
+
|
| 147 |
+
// get type
|
| 148 |
+
var type = opts.type || 'attachment'
|
| 149 |
+
|
| 150 |
+
// get parameters
|
| 151 |
+
var params = createparams(filename, opts.fallback)
|
| 152 |
+
|
| 153 |
+
// format into string
|
| 154 |
+
return format(new ContentDisposition(type, params))
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/**
|
| 158 |
+
* Create parameters object from filename and fallback.
|
| 159 |
+
*
|
| 160 |
+
* @param {string} [filename]
|
| 161 |
+
* @param {string|boolean} [fallback=true]
|
| 162 |
+
* @return {object}
|
| 163 |
+
* @private
|
| 164 |
+
*/
|
| 165 |
+
|
| 166 |
+
function createparams (filename, fallback) {
|
| 167 |
+
if (filename === undefined) {
|
| 168 |
+
return
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
var params = {}
|
| 172 |
+
|
| 173 |
+
if (typeof filename !== 'string') {
|
| 174 |
+
throw new TypeError('filename must be a string')
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
// fallback defaults to true
|
| 178 |
+
if (fallback === undefined) {
|
| 179 |
+
fallback = true
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
if (typeof fallback !== 'string' && typeof fallback !== 'boolean') {
|
| 183 |
+
throw new TypeError('fallback must be a string or boolean')
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
if (typeof fallback === 'string' && NON_LATIN1_REGEXP.test(fallback)) {
|
| 187 |
+
throw new TypeError('fallback must be ISO-8859-1 string')
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
// restrict to file base name
|
| 191 |
+
var name = basename(filename)
|
| 192 |
+
|
| 193 |
+
// determine if name is suitable for quoted string
|
| 194 |
+
var isQuotedString = TEXT_REGEXP.test(name)
|
| 195 |
+
|
| 196 |
+
// generate fallback name
|
| 197 |
+
var fallbackName = typeof fallback !== 'string'
|
| 198 |
+
? fallback && getlatin1(name)
|
| 199 |
+
: basename(fallback)
|
| 200 |
+
var hasFallback = typeof fallbackName === 'string' && fallbackName !== name
|
| 201 |
+
|
| 202 |
+
// set extended filename parameter
|
| 203 |
+
if (hasFallback || !isQuotedString || HEX_ESCAPE_REGEXP.test(name)) {
|
| 204 |
+
params['filename*'] = name
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
// set filename parameter
|
| 208 |
+
if (isQuotedString || hasFallback) {
|
| 209 |
+
params.filename = hasFallback
|
| 210 |
+
? fallbackName
|
| 211 |
+
: name
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
return params
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
/**
|
| 218 |
+
* Format object to Content-Disposition header.
|
| 219 |
+
*
|
| 220 |
+
* @param {object} obj
|
| 221 |
+
* @param {string} obj.type
|
| 222 |
+
* @param {object} [obj.parameters]
|
| 223 |
+
* @return {string}
|
| 224 |
+
* @private
|
| 225 |
+
*/
|
| 226 |
+
|
| 227 |
+
function format (obj) {
|
| 228 |
+
var parameters = obj.parameters
|
| 229 |
+
var type = obj.type
|
| 230 |
+
|
| 231 |
+
if (!type || typeof type !== 'string' || !TOKEN_REGEXP.test(type)) {
|
| 232 |
+
throw new TypeError('invalid type')
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
// start with normalized type
|
| 236 |
+
var string = String(type).toLowerCase()
|
| 237 |
+
|
| 238 |
+
// append parameters
|
| 239 |
+
if (parameters && typeof parameters === 'object') {
|
| 240 |
+
var param
|
| 241 |
+
var params = Object.keys(parameters).sort()
|
| 242 |
+
|
| 243 |
+
for (var i = 0; i < params.length; i++) {
|
| 244 |
+
param = params[i]
|
| 245 |
+
|
| 246 |
+
var val = param.substr(-1) === '*'
|
| 247 |
+
? ustring(parameters[param])
|
| 248 |
+
: qstring(parameters[param])
|
| 249 |
+
|
| 250 |
+
string += '; ' + param + '=' + val
|
| 251 |
+
}
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
return string
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
/**
|
| 258 |
+
* Decode a RFC 5987 field value (gracefully).
|
| 259 |
+
*
|
| 260 |
+
* @param {string} str
|
| 261 |
+
* @return {string}
|
| 262 |
+
* @private
|
| 263 |
+
*/
|
| 264 |
+
|
| 265 |
+
function decodefield (str) {
|
| 266 |
+
var match = EXT_VALUE_REGEXP.exec(str)
|
| 267 |
+
|
| 268 |
+
if (!match) {
|
| 269 |
+
throw new TypeError('invalid extended field value')
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
var charset = match[1].toLowerCase()
|
| 273 |
+
var encoded = match[2]
|
| 274 |
+
var value
|
| 275 |
+
|
| 276 |
+
// to binary string
|
| 277 |
+
var binary = encoded.replace(HEX_ESCAPE_REPLACE_REGEXP, pdecode)
|
| 278 |
+
|
| 279 |
+
switch (charset) {
|
| 280 |
+
case 'iso-8859-1':
|
| 281 |
+
value = getlatin1(binary)
|
| 282 |
+
break
|
| 283 |
+
case 'utf-8':
|
| 284 |
+
value = Buffer.from(binary, 'binary').toString('utf8')
|
| 285 |
+
break
|
| 286 |
+
default:
|
| 287 |
+
throw new TypeError('unsupported charset in extended field')
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
return value
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
/**
|
| 294 |
+
* Get ISO-8859-1 version of string.
|
| 295 |
+
*
|
| 296 |
+
* @param {string} val
|
| 297 |
+
* @return {string}
|
| 298 |
+
* @private
|
| 299 |
+
*/
|
| 300 |
+
|
| 301 |
+
function getlatin1 (val) {
|
| 302 |
+
// simple Unicode -> ISO-8859-1 transformation
|
| 303 |
+
return String(val).replace(NON_LATIN1_REGEXP, '?')
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
/**
|
| 307 |
+
* Parse Content-Disposition header string.
|
| 308 |
+
*
|
| 309 |
+
* @param {string} string
|
| 310 |
+
* @return {object}
|
| 311 |
+
* @public
|
| 312 |
+
*/
|
| 313 |
+
|
| 314 |
+
function parse (string) {
|
| 315 |
+
if (!string || typeof string !== 'string') {
|
| 316 |
+
throw new TypeError('argument string is required')
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
var match = DISPOSITION_TYPE_REGEXP.exec(string)
|
| 320 |
+
|
| 321 |
+
if (!match) {
|
| 322 |
+
throw new TypeError('invalid type format')
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
// normalize type
|
| 326 |
+
var index = match[0].length
|
| 327 |
+
var type = match[1].toLowerCase()
|
| 328 |
+
|
| 329 |
+
var key
|
| 330 |
+
var names = []
|
| 331 |
+
var params = {}
|
| 332 |
+
var value
|
| 333 |
+
|
| 334 |
+
// calculate index to start at
|
| 335 |
+
index = PARAM_REGEXP.lastIndex = match[0].substr(-1) === ';'
|
| 336 |
+
? index - 1
|
| 337 |
+
: index
|
| 338 |
+
|
| 339 |
+
// match parameters
|
| 340 |
+
while ((match = PARAM_REGEXP.exec(string))) {
|
| 341 |
+
if (match.index !== index) {
|
| 342 |
+
throw new TypeError('invalid parameter format')
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
index += match[0].length
|
| 346 |
+
key = match[1].toLowerCase()
|
| 347 |
+
value = match[2]
|
| 348 |
+
|
| 349 |
+
if (names.indexOf(key) !== -1) {
|
| 350 |
+
throw new TypeError('invalid duplicate parameter')
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
names.push(key)
|
| 354 |
+
|
| 355 |
+
if (key.indexOf('*') + 1 === key.length) {
|
| 356 |
+
// decode extended value
|
| 357 |
+
key = key.slice(0, -1)
|
| 358 |
+
value = decodefield(value)
|
| 359 |
+
|
| 360 |
+
// overwrite existing value
|
| 361 |
+
params[key] = value
|
| 362 |
+
continue
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
if (typeof params[key] === 'string') {
|
| 366 |
+
continue
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
if (value[0] === '"') {
|
| 370 |
+
// remove quotes and escapes
|
| 371 |
+
value = value
|
| 372 |
+
.substr(1, value.length - 2)
|
| 373 |
+
.replace(QESC_REGEXP, '$1')
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
params[key] = value
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
if (index !== -1 && index !== string.length) {
|
| 380 |
+
throw new TypeError('invalid parameter format')
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
return new ContentDisposition(type, params)
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
/**
|
| 387 |
+
* Percent decode a single character.
|
| 388 |
+
*
|
| 389 |
+
* @param {string} str
|
| 390 |
+
* @param {string} hex
|
| 391 |
+
* @return {string}
|
| 392 |
+
* @private
|
| 393 |
+
*/
|
| 394 |
+
|
| 395 |
+
function pdecode (str, hex) {
|
| 396 |
+
return String.fromCharCode(parseInt(hex, 16))
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
/**
|
| 400 |
+
* Percent encode a single character.
|
| 401 |
+
*
|
| 402 |
+
* @param {string} char
|
| 403 |
+
* @return {string}
|
| 404 |
+
* @private
|
| 405 |
+
*/
|
| 406 |
+
|
| 407 |
+
function pencode (char) {
|
| 408 |
+
return '%' + String(char)
|
| 409 |
+
.charCodeAt(0)
|
| 410 |
+
.toString(16)
|
| 411 |
+
.toUpperCase()
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
/**
|
| 415 |
+
* Quote a string for HTTP.
|
| 416 |
+
*
|
| 417 |
+
* @param {string} val
|
| 418 |
+
* @return {string}
|
| 419 |
+
* @private
|
| 420 |
+
*/
|
| 421 |
+
|
| 422 |
+
function qstring (val) {
|
| 423 |
+
var str = String(val)
|
| 424 |
+
|
| 425 |
+
return '"' + str.replace(QUOTE_REGEXP, '\\$1') + '"'
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
/**
|
| 429 |
+
* Encode a Unicode string for HTTP (RFC 5987).
|
| 430 |
+
*
|
| 431 |
+
* @param {string} val
|
| 432 |
+
* @return {string}
|
| 433 |
+
* @private
|
| 434 |
+
*/
|
| 435 |
+
|
| 436 |
+
function ustring (val) {
|
| 437 |
+
var str = String(val)
|
| 438 |
+
|
| 439 |
+
// percent encode as UTF-8
|
| 440 |
+
var encoded = encodeURIComponent(str)
|
| 441 |
+
.replace(ENCODE_URL_ATTR_CHAR_REGEXP, pencode)
|
| 442 |
+
|
| 443 |
+
return 'UTF-8\'\'' + encoded
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
/**
|
| 447 |
+
* Class for parsed Content-Disposition header for v8 optimization
|
| 448 |
+
*
|
| 449 |
+
* @public
|
| 450 |
+
* @param {string} type
|
| 451 |
+
* @param {object} parameters
|
| 452 |
+
* @constructor
|
| 453 |
+
*/
|
| 454 |
+
|
| 455 |
+
function ContentDisposition (type, parameters) {
|
| 456 |
+
this.type = type
|
| 457 |
+
this.parameters = parameters
|
| 458 |
+
}
|
node_modules/content-disposition/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "content-disposition",
|
| 3 |
+
"description": "Create and parse Content-Disposition header",
|
| 4 |
+
"version": "0.5.4",
|
| 5 |
+
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
|
| 6 |
+
"license": "MIT",
|
| 7 |
+
"keywords": [
|
| 8 |
+
"content-disposition",
|
| 9 |
+
"http",
|
| 10 |
+
"rfc6266",
|
| 11 |
+
"res"
|
| 12 |
+
],
|
| 13 |
+
"repository": "jshttp/content-disposition",
|
| 14 |
+
"dependencies": {
|
| 15 |
+
"safe-buffer": "5.2.1"
|
| 16 |
+
},
|
| 17 |
+
"devDependencies": {
|
| 18 |
+
"deep-equal": "1.0.1",
|
| 19 |
+
"eslint": "7.32.0",
|
| 20 |
+
"eslint-config-standard": "13.0.1",
|
| 21 |
+
"eslint-plugin-import": "2.25.3",
|
| 22 |
+
"eslint-plugin-markdown": "2.2.1",
|
| 23 |
+
"eslint-plugin-node": "11.1.0",
|
| 24 |
+
"eslint-plugin-promise": "5.2.0",
|
| 25 |
+
"eslint-plugin-standard": "4.1.0",
|
| 26 |
+
"istanbul": "0.4.5",
|
| 27 |
+
"mocha": "9.1.3"
|
| 28 |
+
},
|
| 29 |
+
"files": [
|
| 30 |
+
"LICENSE",
|
| 31 |
+
"HISTORY.md",
|
| 32 |
+
"README.md",
|
| 33 |
+
"index.js"
|
| 34 |
+
],
|
| 35 |
+
"engines": {
|
| 36 |
+
"node": ">= 0.6"
|
| 37 |
+
},
|
| 38 |
+
"scripts": {
|
| 39 |
+
"lint": "eslint .",
|
| 40 |
+
"test": "mocha --reporter spec --bail --check-leaks test/",
|
| 41 |
+
"test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/",
|
| 42 |
+
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/"
|
| 43 |
+
}
|
| 44 |
+
}
|
node_modules/content-type/HISTORY.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1.0.5 / 2023-01-29
|
| 2 |
+
==================
|
| 3 |
+
|
| 4 |
+
* perf: skip value escaping when unnecessary
|
| 5 |
+
|
| 6 |
+
1.0.4 / 2017-09-11
|
| 7 |
+
==================
|
| 8 |
+
|
| 9 |
+
* perf: skip parameter parsing when no parameters
|
| 10 |
+
|
| 11 |
+
1.0.3 / 2017-09-10
|
| 12 |
+
==================
|
| 13 |
+
|
| 14 |
+
* perf: remove argument reassignment
|
| 15 |
+
|
| 16 |
+
1.0.2 / 2016-05-09
|
| 17 |
+
==================
|
| 18 |
+
|
| 19 |
+
* perf: enable strict mode
|
| 20 |
+
|
| 21 |
+
1.0.1 / 2015-02-13
|
| 22 |
+
==================
|
| 23 |
+
|
| 24 |
+
* Improve missing `Content-Type` header error message
|
| 25 |
+
|
| 26 |
+
1.0.0 / 2015-02-01
|
| 27 |
+
==================
|
| 28 |
+
|
| 29 |
+
* Initial implementation, derived from `media-typer@0.3.0`
|
node_modules/content-type/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
(The MIT License)
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2015 Douglas Christopher Wilson
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining
|
| 6 |
+
a copy of this software and associated documentation files (the
|
| 7 |
+
'Software'), to deal in the Software without restriction, including
|
| 8 |
+
without limitation the rights to use, copy, modify, merge, publish,
|
| 9 |
+
distribute, sublicense, and/or sell copies of the Software, and to
|
| 10 |
+
permit persons to whom the Software is furnished to do so, subject to
|
| 11 |
+
the following conditions:
|
| 12 |
+
|
| 13 |
+
The above copyright notice and this permission notice shall be
|
| 14 |
+
included in all copies or substantial portions of the Software.
|
| 15 |
+
|
| 16 |
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
| 17 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 18 |
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
| 19 |
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
| 20 |
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
| 21 |
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
| 22 |
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
node_modules/content-type/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# content-type
|
| 2 |
+
|
| 3 |
+
[![NPM Version][npm-version-image]][npm-url]
|
| 4 |
+
[![NPM Downloads][npm-downloads-image]][npm-url]
|
| 5 |
+
[![Node.js Version][node-image]][node-url]
|
| 6 |
+
[![Build Status][ci-image]][ci-url]
|
| 7 |
+
[![Coverage Status][coveralls-image]][coveralls-url]
|
| 8 |
+
|
| 9 |
+
Create and parse HTTP Content-Type header according to RFC 7231
|
| 10 |
+
|
| 11 |
+
## Installation
|
| 12 |
+
|
| 13 |
+
```sh
|
| 14 |
+
$ npm install content-type
|
| 15 |
+
```
|
| 16 |
+
|
| 17 |
+
## API
|
| 18 |
+
|
| 19 |
+
```js
|
| 20 |
+
var contentType = require('content-type')
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
### contentType.parse(string)
|
| 24 |
+
|
| 25 |
+
```js
|
| 26 |
+
var obj = contentType.parse('image/svg+xml; charset=utf-8')
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
Parse a `Content-Type` header. This will return an object with the following
|
| 30 |
+
properties (examples are shown for the string `'image/svg+xml; charset=utf-8'`):
|
| 31 |
+
|
| 32 |
+
- `type`: The media type (the type and subtype, always lower case).
|
| 33 |
+
Example: `'image/svg+xml'`
|
| 34 |
+
|
| 35 |
+
- `parameters`: An object of the parameters in the media type (name of parameter
|
| 36 |
+
always lower case). Example: `{charset: 'utf-8'}`
|
| 37 |
+
|
| 38 |
+
Throws a `TypeError` if the string is missing or invalid.
|
| 39 |
+
|
| 40 |
+
### contentType.parse(req)
|
| 41 |
+
|
| 42 |
+
```js
|
| 43 |
+
var obj = contentType.parse(req)
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
Parse the `Content-Type` header from the given `req`. Short-cut for
|
| 47 |
+
`contentType.parse(req.headers['content-type'])`.
|
| 48 |
+
|
| 49 |
+
Throws a `TypeError` if the `Content-Type` header is missing or invalid.
|
| 50 |
+
|
| 51 |
+
### contentType.parse(res)
|
| 52 |
+
|
| 53 |
+
```js
|
| 54 |
+
var obj = contentType.parse(res)
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
Parse the `Content-Type` header set on the given `res`. Short-cut for
|
| 58 |
+
`contentType.parse(res.getHeader('content-type'))`.
|
| 59 |
+
|
| 60 |
+
Throws a `TypeError` if the `Content-Type` header is missing or invalid.
|
| 61 |
+
|
| 62 |
+
### contentType.format(obj)
|
| 63 |
+
|
| 64 |
+
```js
|
| 65 |
+
var str = contentType.format({
|
| 66 |
+
type: 'image/svg+xml',
|
| 67 |
+
parameters: { charset: 'utf-8' }
|
| 68 |
+
})
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
Format an object into a `Content-Type` header. This will return a string of the
|
| 72 |
+
content type for the given object with the following properties (examples are
|
| 73 |
+
shown that produce the string `'image/svg+xml; charset=utf-8'`):
|
| 74 |
+
|
| 75 |
+
- `type`: The media type (will be lower-cased). Example: `'image/svg+xml'`
|
| 76 |
+
|
| 77 |
+
- `parameters`: An object of the parameters in the media type (name of the
|
| 78 |
+
parameter will be lower-cased). Example: `{charset: 'utf-8'}`
|
| 79 |
+
|
| 80 |
+
Throws a `TypeError` if the object contains an invalid type or parameter names.
|
| 81 |
+
|
| 82 |
+
## License
|
| 83 |
+
|
| 84 |
+
[MIT](LICENSE)
|
| 85 |
+
|
| 86 |
+
[ci-image]: https://badgen.net/github/checks/jshttp/content-type/master?label=ci
|
| 87 |
+
[ci-url]: https://github.com/jshttp/content-type/actions/workflows/ci.yml
|
| 88 |
+
[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/content-type/master
|
| 89 |
+
[coveralls-url]: https://coveralls.io/r/jshttp/content-type?branch=master
|
| 90 |
+
[node-image]: https://badgen.net/npm/node/content-type
|
| 91 |
+
[node-url]: https://nodejs.org/en/download
|
| 92 |
+
[npm-downloads-image]: https://badgen.net/npm/dm/content-type
|
| 93 |
+
[npm-url]: https://npmjs.org/package/content-type
|
| 94 |
+
[npm-version-image]: https://badgen.net/npm/v/content-type
|