@remotion/renderer 4.0.462 → 4.0.464
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/BrowserFetcher.js +2 -5
- package/dist/browser/extract-zip-archive.d.ts +1 -0
- package/dist/browser/extract-zip-archive.js +144 -0
- package/dist/esm/error-handling.mjs +5 -0
- package/dist/esm/index.mjs +1899 -353
- package/dist/print-useful-error-message.js +6 -0
- package/package.json +14 -15
- package/vendor/yauzl-patched/LICENSE +21 -0
- package/vendor/yauzl-patched/buffer-crc32.js +111 -0
- package/vendor/yauzl-patched/fd-slicer.js +326 -0
- package/vendor/yauzl-patched/index.d.ts +23 -0
- package/vendor/yauzl-patched/index.js +969 -0
- package/vendor/yauzl-patched/pend.js +55 -0
- package/dist/options/experimental-visual-mode.d.ts +0 -16
- package/dist/options/experimental-visual-mode.js +0 -30
|
@@ -53,6 +53,11 @@ const printUsefulErrorMessage = (err, logLevel, indent) => {
|
|
|
53
53
|
logger_1.Log.info({ indent, logLevel });
|
|
54
54
|
logger_1.Log.info({ indent, logLevel }, '💡 This error indicates that your Lambda concurrency limit is too low. See: https://www.remotion.dev/docs/lambda/troubleshooting/rate-limit');
|
|
55
55
|
}
|
|
56
|
+
if (err.message.includes('Failed to acquire WebGL2 context') ||
|
|
57
|
+
err.message.includes('Failed to acquire WebGL context')) {
|
|
58
|
+
logger_1.Log.info({ indent, logLevel });
|
|
59
|
+
logger_1.Log.info({ indent, logLevel }, '💡 Get help for this issue at https://remotion.dev/docs/troubleshooting/webgl2-context');
|
|
60
|
+
}
|
|
56
61
|
if (err.message.includes('Error creating WebGL context')) {
|
|
57
62
|
logger_1.Log.info({ indent, logLevel });
|
|
58
63
|
logger_1.Log.warn({
|
|
@@ -63,6 +68,7 @@ const printUsefulErrorMessage = (err, logLevel, indent) => {
|
|
|
63
68
|
indent,
|
|
64
69
|
logLevel,
|
|
65
70
|
}, "💡 Check how it's done at https://www.remotion.dev/docs/chromium-flags#--gl");
|
|
71
|
+
logger_1.Log.info({ indent, logLevel }, '💡 Get help for this issue at https://remotion.dev/docs/troubleshooting/webgl2-context');
|
|
66
72
|
}
|
|
67
73
|
if (err.message.includes('The bucket does not allow ACLs')) {
|
|
68
74
|
logger_1.Log.info({ indent, logLevel });
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"url": "https://github.com/remotion-dev/remotion/tree/main/packages/renderer"
|
|
4
4
|
},
|
|
5
5
|
"name": "@remotion/renderer",
|
|
6
|
-
"version": "4.0.
|
|
6
|
+
"version": "4.0.464",
|
|
7
7
|
"description": "Render Remotion videos using Node.js or Bun",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"types": "dist/index.d.ts",
|
|
@@ -22,12 +22,11 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"execa": "5.1.1",
|
|
25
|
-
"
|
|
26
|
-
"remotion": "4.0.
|
|
27
|
-
"@remotion/streaming": "4.0.462",
|
|
25
|
+
"remotion": "4.0.464",
|
|
26
|
+
"@remotion/streaming": "4.0.464",
|
|
28
27
|
"source-map": "0.8.0-beta.0",
|
|
29
|
-
"ws": "8.
|
|
30
|
-
"@remotion/licensing": "4.0.
|
|
28
|
+
"ws": "8.20.1",
|
|
29
|
+
"@remotion/licensing": "4.0.464"
|
|
31
30
|
},
|
|
32
31
|
"peerDependencies": {
|
|
33
32
|
"react": ">=16.8.0",
|
|
@@ -41,19 +40,19 @@
|
|
|
41
40
|
"react-dom": "19.2.3",
|
|
42
41
|
"@typescript/native-preview": "7.0.0-dev.20260217.1",
|
|
43
42
|
"@types/ws": "8.5.10",
|
|
44
|
-
"@remotion/example-videos": "4.0.
|
|
45
|
-
"@remotion/eslint-config-internal": "4.0.
|
|
43
|
+
"@remotion/example-videos": "4.0.464",
|
|
44
|
+
"@remotion/eslint-config-internal": "4.0.464",
|
|
46
45
|
"eslint": "9.19.0",
|
|
47
46
|
"@types/node": "20.12.14"
|
|
48
47
|
},
|
|
49
48
|
"optionalDependencies": {
|
|
50
|
-
"@remotion/compositor-darwin-arm64": "4.0.
|
|
51
|
-
"@remotion/compositor-darwin-x64": "4.0.
|
|
52
|
-
"@remotion/compositor-linux-arm64-gnu": "4.0.
|
|
53
|
-
"@remotion/compositor-linux-arm64-musl": "4.0.
|
|
54
|
-
"@remotion/compositor-linux-x64-gnu": "4.0.
|
|
55
|
-
"@remotion/compositor-linux-x64-musl": "4.0.
|
|
56
|
-
"@remotion/compositor-win32-x64-msvc": "4.0.
|
|
49
|
+
"@remotion/compositor-darwin-arm64": "4.0.464",
|
|
50
|
+
"@remotion/compositor-darwin-x64": "4.0.464",
|
|
51
|
+
"@remotion/compositor-linux-arm64-gnu": "4.0.464",
|
|
52
|
+
"@remotion/compositor-linux-arm64-musl": "4.0.464",
|
|
53
|
+
"@remotion/compositor-linux-x64-gnu": "4.0.464",
|
|
54
|
+
"@remotion/compositor-linux-x64-musl": "4.0.464",
|
|
55
|
+
"@remotion/compositor-win32-x64-msvc": "4.0.464"
|
|
57
56
|
},
|
|
58
57
|
"keywords": [
|
|
59
58
|
"remotion",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014 Josh Wolfe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
var Buffer = require('buffer').Buffer;
|
|
2
|
+
|
|
3
|
+
var CRC_TABLE = [
|
|
4
|
+
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
|
|
5
|
+
0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
|
|
6
|
+
0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
|
|
7
|
+
0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
|
|
8
|
+
0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
|
|
9
|
+
0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
|
|
10
|
+
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
|
|
11
|
+
0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
|
|
12
|
+
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
|
|
13
|
+
0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
|
|
14
|
+
0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
|
|
15
|
+
0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
|
|
16
|
+
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
|
|
17
|
+
0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
|
|
18
|
+
0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
|
|
19
|
+
0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
|
|
20
|
+
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
|
|
21
|
+
0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
|
|
22
|
+
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
|
|
23
|
+
0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
|
|
24
|
+
0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
|
|
25
|
+
0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
|
|
26
|
+
0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
|
|
27
|
+
0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
|
28
|
+
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
|
|
29
|
+
0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
|
|
30
|
+
0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
|
|
31
|
+
0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
|
|
32
|
+
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
|
|
33
|
+
0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
|
|
34
|
+
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
|
|
35
|
+
0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
|
|
36
|
+
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
|
|
37
|
+
0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
|
|
38
|
+
0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
|
|
39
|
+
0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
|
|
40
|
+
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
|
|
41
|
+
0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
|
|
42
|
+
0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
|
|
43
|
+
0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
|
|
44
|
+
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
|
|
45
|
+
0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
|
|
46
|
+
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
|
|
47
|
+
0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
|
|
48
|
+
0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
|
|
49
|
+
0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
|
|
50
|
+
0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
|
|
51
|
+
0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
|
52
|
+
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
|
|
53
|
+
0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
|
|
54
|
+
0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
|
|
55
|
+
0x2d02ef8d
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
if (typeof Int32Array !== 'undefined') {
|
|
59
|
+
CRC_TABLE = new Int32Array(CRC_TABLE);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function ensureBuffer(input) {
|
|
63
|
+
if (Buffer.isBuffer(input)) {
|
|
64
|
+
return input;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
var hasNewBufferAPI =
|
|
68
|
+
typeof Buffer.alloc === "function" &&
|
|
69
|
+
typeof Buffer.from === "function";
|
|
70
|
+
|
|
71
|
+
if (typeof input === "number") {
|
|
72
|
+
return hasNewBufferAPI ? Buffer.alloc(input) : new Buffer(input);
|
|
73
|
+
}
|
|
74
|
+
else if (typeof input === "string") {
|
|
75
|
+
return hasNewBufferAPI ? Buffer.from(input) : new Buffer(input);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
throw new Error("input must be buffer, number, or string, received " +
|
|
79
|
+
typeof input);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function bufferizeInt(num) {
|
|
84
|
+
var tmp = ensureBuffer(4);
|
|
85
|
+
tmp.writeInt32BE(num, 0);
|
|
86
|
+
return tmp;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function _crc32(buf, previous) {
|
|
90
|
+
buf = ensureBuffer(buf);
|
|
91
|
+
if (Buffer.isBuffer(previous)) {
|
|
92
|
+
previous = previous.readUInt32BE(0);
|
|
93
|
+
}
|
|
94
|
+
var crc = ~~previous ^ -1;
|
|
95
|
+
for (var n = 0; n < buf.length; n++) {
|
|
96
|
+
crc = CRC_TABLE[(crc ^ buf[n]) & 0xff] ^ (crc >>> 8);
|
|
97
|
+
}
|
|
98
|
+
return (crc ^ -1);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function crc32() {
|
|
102
|
+
return bufferizeInt(_crc32.apply(null, arguments));
|
|
103
|
+
}
|
|
104
|
+
crc32.signed = function () {
|
|
105
|
+
return _crc32.apply(null, arguments);
|
|
106
|
+
};
|
|
107
|
+
crc32.unsigned = function () {
|
|
108
|
+
return _crc32.apply(null, arguments) >>> 0;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
module.exports = crc32;
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
// This was adapted from https://github.com/andrewrk/node-fd-slicer by Andrew Kelley under the MIT License.
|
|
2
|
+
var fs = require('fs');
|
|
3
|
+
var util = require('util');
|
|
4
|
+
var stream = require('stream');
|
|
5
|
+
var Readable = stream.Readable;
|
|
6
|
+
var Writable = stream.Writable;
|
|
7
|
+
var PassThrough = stream.PassThrough;
|
|
8
|
+
var Pend = require('./pend');
|
|
9
|
+
var EventEmitter = require('events').EventEmitter;
|
|
10
|
+
|
|
11
|
+
exports.createFromBuffer = createFromBuffer;
|
|
12
|
+
exports.createFromFd = createFromFd;
|
|
13
|
+
exports.BufferSlicer = BufferSlicer;
|
|
14
|
+
exports.FdSlicer = FdSlicer;
|
|
15
|
+
|
|
16
|
+
util.inherits(FdSlicer, EventEmitter);
|
|
17
|
+
function FdSlicer(fd, options) {
|
|
18
|
+
options = options || {};
|
|
19
|
+
EventEmitter.call(this);
|
|
20
|
+
|
|
21
|
+
this.fd = fd;
|
|
22
|
+
this.pend = new Pend();
|
|
23
|
+
this.pend.max = 1;
|
|
24
|
+
this.refCount = 0;
|
|
25
|
+
this.autoClose = !!options.autoClose;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
FdSlicer.prototype.read = function(buffer, offset, length, position, callback) {
|
|
29
|
+
var self = this;
|
|
30
|
+
self.pend.go(function(cb) {
|
|
31
|
+
fs.read(self.fd, buffer, offset, length, position, function(err, bytesRead, buffer) {
|
|
32
|
+
cb();
|
|
33
|
+
callback(err, bytesRead, buffer);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
FdSlicer.prototype.write = function(buffer, offset, length, position, callback) {
|
|
39
|
+
var self = this;
|
|
40
|
+
self.pend.go(function(cb) {
|
|
41
|
+
fs.write(self.fd, buffer, offset, length, position, function(err, written, buffer) {
|
|
42
|
+
cb();
|
|
43
|
+
callback(err, written, buffer);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
FdSlicer.prototype.createReadStream = function(options) {
|
|
49
|
+
return new ReadStream(this, options);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
FdSlicer.prototype.createWriteStream = function(options) {
|
|
53
|
+
return new WriteStream(this, options);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
FdSlicer.prototype.ref = function() {
|
|
57
|
+
this.refCount += 1;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
FdSlicer.prototype.unref = function() {
|
|
61
|
+
var self = this;
|
|
62
|
+
self.refCount -= 1;
|
|
63
|
+
|
|
64
|
+
if (self.refCount > 0) return;
|
|
65
|
+
if (self.refCount < 0) throw new Error("invalid unref");
|
|
66
|
+
|
|
67
|
+
if (self.autoClose) {
|
|
68
|
+
fs.close(self.fd, onCloseDone);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function onCloseDone(err) {
|
|
72
|
+
if (err) {
|
|
73
|
+
self.emit('error', err);
|
|
74
|
+
} else {
|
|
75
|
+
self.emit('close');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
util.inherits(ReadStream, Readable);
|
|
81
|
+
function ReadStream(context, options) {
|
|
82
|
+
options = options || {};
|
|
83
|
+
Readable.call(this, options);
|
|
84
|
+
|
|
85
|
+
this.context = context;
|
|
86
|
+
this.context.ref();
|
|
87
|
+
|
|
88
|
+
this.start = options.start || 0;
|
|
89
|
+
this.endOffset = options.end;
|
|
90
|
+
this.pos = this.start;
|
|
91
|
+
this._destroyed = false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
ReadStream.prototype._read = function(n) {
|
|
95
|
+
var self = this;
|
|
96
|
+
if (self._destroyed) return;
|
|
97
|
+
|
|
98
|
+
var toRead = Math.min(self._readableState.highWaterMark, n);
|
|
99
|
+
if (self.endOffset != null) {
|
|
100
|
+
toRead = Math.min(toRead, self.endOffset - self.pos);
|
|
101
|
+
}
|
|
102
|
+
if (toRead <= 0) {
|
|
103
|
+
self._destroyed = true;
|
|
104
|
+
self.push(null);
|
|
105
|
+
self.context.unref();
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
self.context.pend.go(function(cb) {
|
|
109
|
+
if (self._destroyed) return cb();
|
|
110
|
+
var buffer = Buffer.allocUnsafe(toRead);
|
|
111
|
+
fs.read(self.context.fd, buffer, 0, toRead, self.pos, function(err, bytesRead) {
|
|
112
|
+
if (self._destroyed) return cb();
|
|
113
|
+
if (err) {
|
|
114
|
+
self.destroy(err);
|
|
115
|
+
} else if (bytesRead === 0) {
|
|
116
|
+
self._destroyed = true;
|
|
117
|
+
self.push(null);
|
|
118
|
+
self.context.unref();
|
|
119
|
+
} else {
|
|
120
|
+
self.pos += bytesRead;
|
|
121
|
+
self.push(buffer.slice(0, bytesRead));
|
|
122
|
+
}
|
|
123
|
+
cb();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
ReadStream.prototype.destroy = function(err) {
|
|
129
|
+
if (err == null && !this.readableEnded) {
|
|
130
|
+
err = new Error("stream _destroyed");
|
|
131
|
+
}
|
|
132
|
+
return Readable.prototype.destroy.call(this, err);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
ReadStream.prototype._destroy = function(err, cb) {
|
|
136
|
+
if (!this._destroyed) {
|
|
137
|
+
this._destroyed = true;
|
|
138
|
+
this.context.unref();
|
|
139
|
+
}
|
|
140
|
+
cb(err);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
util.inherits(WriteStream, Writable);
|
|
144
|
+
function WriteStream(context, options) {
|
|
145
|
+
options = options || {};
|
|
146
|
+
Writable.call(this, options);
|
|
147
|
+
|
|
148
|
+
this.context = context;
|
|
149
|
+
this.context.ref();
|
|
150
|
+
|
|
151
|
+
this.start = options.start || 0;
|
|
152
|
+
this.endOffset = (options.end == null) ? Infinity : +options.end;
|
|
153
|
+
this.bytesWritten = 0;
|
|
154
|
+
this.pos = this.start;
|
|
155
|
+
this._destroyed = false;
|
|
156
|
+
|
|
157
|
+
this.on('finish', this.destroy.bind(this));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
WriteStream.prototype._write = function(buffer, encoding, callback) {
|
|
161
|
+
var self = this;
|
|
162
|
+
if (self._destroyed) return;
|
|
163
|
+
|
|
164
|
+
if (self.pos + buffer.length > self.endOffset) {
|
|
165
|
+
var err = new Error("maximum file length exceeded");
|
|
166
|
+
err.code = 'ETOOBIG';
|
|
167
|
+
self.destroy();
|
|
168
|
+
callback(err);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
self.context.pend.go(function(cb) {
|
|
172
|
+
if (self._destroyed) return cb();
|
|
173
|
+
fs.write(self.context.fd, buffer, 0, buffer.length, self.pos, function(err, bytes) {
|
|
174
|
+
if (err) {
|
|
175
|
+
self.destroy();
|
|
176
|
+
cb();
|
|
177
|
+
callback(err);
|
|
178
|
+
} else {
|
|
179
|
+
self.bytesWritten += bytes;
|
|
180
|
+
self.pos += bytes;
|
|
181
|
+
self.emit('progress');
|
|
182
|
+
cb();
|
|
183
|
+
callback();
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
WriteStream.prototype._destroy = function(err, cb) {
|
|
190
|
+
if (!this._destroyed) {
|
|
191
|
+
this._destroyed = true;
|
|
192
|
+
this.context.unref();
|
|
193
|
+
}
|
|
194
|
+
cb(err);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
util.inherits(BufferSlicer, EventEmitter);
|
|
198
|
+
function BufferSlicer(buffer, options) {
|
|
199
|
+
EventEmitter.call(this);
|
|
200
|
+
|
|
201
|
+
options = options || {};
|
|
202
|
+
this.refCount = 0;
|
|
203
|
+
this.buffer = buffer;
|
|
204
|
+
this.maxChunkSize = options.maxChunkSize || Number.MAX_SAFE_INTEGER;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
BufferSlicer.prototype.read = function(buffer, offset, length, position, callback) {
|
|
208
|
+
if (!(0 <= offset && offset <= buffer.length)) throw new RangeError("offset outside buffer: 0 <= " + offset + " <= " + buffer.length);
|
|
209
|
+
if (position < 0) throw new RangeError("position is negative: " + position);
|
|
210
|
+
if (offset + length > buffer.length) {
|
|
211
|
+
// The caller's buffer can't hold all the bytes they're trying to read.
|
|
212
|
+
// Clamp the length instead of giving an error.
|
|
213
|
+
// The callback will be informed of fewer than expected bytes written.
|
|
214
|
+
length = buffer.length - offset;
|
|
215
|
+
}
|
|
216
|
+
if (position + length > this.buffer.length) {
|
|
217
|
+
// Clamp any attempt to read past the end of the source buffer.
|
|
218
|
+
length = this.buffer.length - position;
|
|
219
|
+
}
|
|
220
|
+
if (length <= 0) {
|
|
221
|
+
// After any clamping, we're fully out of bounds or otherwise have nothing to do.
|
|
222
|
+
// This isn't an error; it's just zero bytes written.
|
|
223
|
+
setImmediate(function() {
|
|
224
|
+
callback(null, 0);
|
|
225
|
+
});
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
this.buffer.copy(buffer, offset, position, position + length);
|
|
229
|
+
setImmediate(function() {
|
|
230
|
+
callback(null, length);
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
BufferSlicer.prototype.write = function(buffer, offset, length, position, callback) {
|
|
235
|
+
buffer.copy(this.buffer, position, offset, offset + length);
|
|
236
|
+
setImmediate(function() {
|
|
237
|
+
callback(null, length, buffer);
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
BufferSlicer.prototype.createReadStream = function(options) {
|
|
242
|
+
options = options || {};
|
|
243
|
+
var readStream = new PassThrough(options);
|
|
244
|
+
readStream._destroyed = false;
|
|
245
|
+
readStream.start = options.start || 0;
|
|
246
|
+
readStream.endOffset = options.end;
|
|
247
|
+
// by the time this function returns, we'll be done.
|
|
248
|
+
readStream.pos = readStream.endOffset || this.buffer.length;
|
|
249
|
+
|
|
250
|
+
// respect the maxChunkSize option to slice up the chunk into smaller pieces.
|
|
251
|
+
var entireSlice = this.buffer.slice(readStream.start, readStream.pos);
|
|
252
|
+
var offset = 0;
|
|
253
|
+
while (true) {
|
|
254
|
+
var nextOffset = offset + this.maxChunkSize;
|
|
255
|
+
if (nextOffset >= entireSlice.length) {
|
|
256
|
+
// last chunk
|
|
257
|
+
if (offset < entireSlice.length) {
|
|
258
|
+
readStream.write(entireSlice.slice(offset, entireSlice.length));
|
|
259
|
+
}
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
readStream.write(entireSlice.slice(offset, nextOffset));
|
|
263
|
+
offset = nextOffset;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
readStream.end();
|
|
267
|
+
readStream._destroy = function(err, cb) {
|
|
268
|
+
readStream._destroyed = true;
|
|
269
|
+
PassThrough.prototype._destroy.call(readStream, err, cb);
|
|
270
|
+
};
|
|
271
|
+
return readStream;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
BufferSlicer.prototype.createWriteStream = function(options) {
|
|
275
|
+
var bufferSlicer = this;
|
|
276
|
+
options = options || {};
|
|
277
|
+
var writeStream = new Writable(options);
|
|
278
|
+
writeStream.start = options.start || 0;
|
|
279
|
+
writeStream.endOffset = (options.end == null) ? this.buffer.length : +options.end;
|
|
280
|
+
writeStream.bytesWritten = 0;
|
|
281
|
+
writeStream.pos = writeStream.start;
|
|
282
|
+
writeStream._destroyed = false;
|
|
283
|
+
writeStream._write = function(buffer, encoding, callback) {
|
|
284
|
+
if (writeStream._destroyed) return;
|
|
285
|
+
|
|
286
|
+
var end = writeStream.pos + buffer.length;
|
|
287
|
+
if (end > writeStream.endOffset) {
|
|
288
|
+
var err = new Error("maximum file length exceeded");
|
|
289
|
+
err.code = 'ETOOBIG';
|
|
290
|
+
writeStream._destroyed = true;
|
|
291
|
+
callback(err);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
buffer.copy(bufferSlicer.buffer, writeStream.pos, 0, buffer.length);
|
|
295
|
+
|
|
296
|
+
writeStream.bytesWritten += buffer.length;
|
|
297
|
+
writeStream.pos = end;
|
|
298
|
+
writeStream.emit('progress');
|
|
299
|
+
callback();
|
|
300
|
+
};
|
|
301
|
+
writeStream._destroy = function(err, cb) {
|
|
302
|
+
writeStream._destroyed = true;
|
|
303
|
+
cb(err);
|
|
304
|
+
};
|
|
305
|
+
return writeStream;
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
BufferSlicer.prototype.ref = function() {
|
|
309
|
+
this.refCount += 1;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
BufferSlicer.prototype.unref = function() {
|
|
313
|
+
this.refCount -= 1;
|
|
314
|
+
|
|
315
|
+
if (this.refCount < 0) {
|
|
316
|
+
throw new Error("invalid unref");
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
function createFromBuffer(buffer, options) {
|
|
321
|
+
return new BufferSlicer(buffer, options);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function createFromFd(fd, options) {
|
|
325
|
+
return new FdSlicer(fd, options);
|
|
326
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type {EventEmitter} from 'events';
|
|
2
|
+
import type {Readable} from 'stream';
|
|
3
|
+
|
|
4
|
+
export interface Entry {
|
|
5
|
+
fileName: string;
|
|
6
|
+
externalFileAttributes: number;
|
|
7
|
+
versionMadeBy: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ZipFile extends EventEmitter {
|
|
11
|
+
readEntry(): void;
|
|
12
|
+
close(): void;
|
|
13
|
+
openReadStream(
|
|
14
|
+
entry: Entry,
|
|
15
|
+
callback: (err: Error | null, readStream?: Readable) => void,
|
|
16
|
+
): void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function open(
|
|
20
|
+
path: string,
|
|
21
|
+
options: {lazyEntries: true},
|
|
22
|
+
callback?: (err: Error | null, zipfile: ZipFile) => void,
|
|
23
|
+
): void;
|