@unpackjs/core 1.7.2 → 1.7.4

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.
Files changed (52) hide show
  1. package/compiled/css-loader/index.js +20 -20
  2. package/compiled/less-loader/index.js +8 -8
  3. package/compiled/postcss-loader/index.js +8 -8
  4. package/compiled/sass-loader/index.js +9 -8
  5. package/compiled/sass-loader/package.json +1 -1
  6. package/compiled/style-loader/index.js +10 -10
  7. package/dist/bundler-config/chunkSplit.cjs +0 -4
  8. package/dist/bundler-config/chunkSplit.d.ts.map +1 -1
  9. package/dist/bundler-config/chunkSplit.js +0 -4
  10. package/dist/bundler-config/css.cjs +1 -2
  11. package/dist/bundler-config/css.d.ts.map +1 -1
  12. package/dist/bundler-config/css.js +1 -2
  13. package/dist/bundler-config/experimentCss.cjs +4 -1
  14. package/dist/bundler-config/experimentCss.d.ts.map +1 -1
  15. package/dist/bundler-config/experimentCss.js +4 -1
  16. package/dist/bundler-config/index.cjs +6 -6
  17. package/dist/bundler-config/index.d.ts.map +1 -1
  18. package/dist/bundler-config/index.js +6 -6
  19. package/dist/bundler-config/jsMinify.cjs +101 -0
  20. package/dist/bundler-config/jsMinify.d.ts +18 -0
  21. package/dist/bundler-config/jsMinify.d.ts.map +1 -0
  22. package/dist/bundler-config/jsMinify.js +77 -0
  23. package/dist/createUnpack.cjs +7 -2
  24. package/dist/createUnpack.d.ts.map +1 -1
  25. package/dist/createUnpack.js +7 -2
  26. package/dist/lightningcss/minimizer.cjs +1 -1
  27. package/dist/lightningcss/minimizer.js +1 -1
  28. package/dist/plugin-progress/webpack.d.ts.map +1 -1
  29. package/dist/prebundleDeps.cjs +2 -1
  30. package/dist/prebundleDeps.d.ts.map +1 -1
  31. package/dist/prebundleDeps.js +2 -1
  32. package/dist/run/dev.cjs +1 -1
  33. package/dist/run/dev.js +1 -1
  34. package/dist/types/config.d.ts +5 -2
  35. package/dist/types/config.d.ts.map +1 -1
  36. package/package.json +8 -10
  37. package/dist/thread-loader/WorkerError.cjs +0 -41
  38. package/dist/thread-loader/WorkerError.js +0 -31
  39. package/dist/thread-loader/WorkerPool.cjs +0 -407
  40. package/dist/thread-loader/WorkerPool.js +0 -387
  41. package/dist/thread-loader/index.cjs +0 -100
  42. package/dist/thread-loader/index.js +0 -85
  43. package/dist/thread-loader/readBuffer.cjs +0 -55
  44. package/dist/thread-loader/readBuffer.js +0 -45
  45. package/dist/thread-loader/serializer.cjs +0 -46
  46. package/dist/thread-loader/serializer.js +0 -31
  47. package/dist/thread-loader/utils.cjs +0 -84
  48. package/dist/thread-loader/utils.js +0 -60
  49. package/dist/thread-loader/worker.cjs +0 -377
  50. package/dist/thread-loader/worker.js +0 -382
  51. package/dist/thread-loader/workerPools.cjs +0 -57
  52. package/dist/thread-loader/workerPools.js +0 -33
@@ -1,387 +0,0 @@
1
- import { createRequire } from 'node:module';
2
- var require = createRequire(import.meta['url']);
3
-
4
- import path from "path";
5
- import { fileURLToPath } from "url";
6
- var getFilename = () => fileURLToPath(import.meta.url);
7
- var getDirname = () => path.dirname(getFilename());
8
- var __dirname = /* @__PURE__ */ getDirname();
9
- var __filename = /* @__PURE__ */ getFilename();
10
- import childProcess from "node:child_process";
11
- const asyncMapSeries = require("neo-async/mapSeries.js");
12
- const asyncQueue = require("neo-async/queue.js");
13
- import WorkerError from "./WorkerError.js";
14
- import readBuffer from "./readBuffer.js";
15
- import { replacer, reviver } from "./serializer.js";
16
- const workerPath = require.resolve("./worker");
17
- let workerId = 0;
18
- class PoolWorker {
19
- constructor(options, onJobDone) {
20
- this.disposed = false;
21
- this.nextJobId = 0;
22
- this.jobs = /* @__PURE__ */ Object.create(null);
23
- this.activeJobs = 0;
24
- this.onJobDone = onJobDone;
25
- this.id = workerId;
26
- workerId += 1;
27
- const sanitizedNodeArgs = (options.nodeArgs || []).filter((opt) => !!opt);
28
- this.worker = childProcess.spawn(
29
- process.execPath,
30
- [].concat(sanitizedNodeArgs).concat(workerPath, options.parallelJobs),
31
- {
32
- detached: true,
33
- stdio: ["ignore", "pipe", "pipe", "pipe", "pipe"]
34
- }
35
- );
36
- this.worker.unref();
37
- if (!this.worker.stdio) {
38
- throw new Error(
39
- `Failed to create the worker pool with workerId: ${workerId} and ${""}configuration: ${JSON.stringify(
40
- options
41
- )}. Please verify if you hit the OS open files limit.`
42
- );
43
- }
44
- const [, , , readPipe, writePipe] = this.worker.stdio;
45
- this.readPipe = readPipe;
46
- this.writePipe = writePipe;
47
- this.listenStdOutAndErrFromWorker(this.worker.stdout, this.worker.stderr);
48
- this.readNextMessage();
49
- }
50
- listenStdOutAndErrFromWorker(workerStdout, workerStderr) {
51
- if (workerStdout) {
52
- workerStdout.on("data", this.writeToStdout);
53
- }
54
- if (workerStderr) {
55
- workerStderr.on("data", this.writeToStderr);
56
- }
57
- }
58
- ignoreStdOutAndErrFromWorker(workerStdout, workerStderr) {
59
- if (workerStdout) {
60
- workerStdout.removeListener("data", this.writeToStdout);
61
- }
62
- if (workerStderr) {
63
- workerStderr.removeListener("data", this.writeToStderr);
64
- }
65
- }
66
- writeToStdout(data) {
67
- if (!this.disposed) {
68
- process.stdout.write(data);
69
- }
70
- }
71
- writeToStderr(data) {
72
- if (!this.disposed) {
73
- process.stderr.write(data);
74
- }
75
- }
76
- run(data, callback) {
77
- const jobId = this.nextJobId;
78
- this.nextJobId += 1;
79
- this.jobs[jobId] = { data, callback };
80
- this.activeJobs += 1;
81
- this.writeJson({
82
- type: "job",
83
- id: jobId,
84
- data
85
- });
86
- }
87
- warmup(requires) {
88
- this.writeJson({
89
- type: "warmup",
90
- requires
91
- });
92
- }
93
- writeJson(data) {
94
- const lengthBuffer = Buffer.alloc(4);
95
- const messageBuffer = Buffer.from(JSON.stringify(data, replacer), "utf-8");
96
- lengthBuffer.writeInt32BE(messageBuffer.length, 0);
97
- this.writePipe.write(lengthBuffer);
98
- this.writePipe.write(messageBuffer);
99
- }
100
- writeEnd() {
101
- const lengthBuffer = Buffer.alloc(4);
102
- lengthBuffer.writeInt32BE(0, 0);
103
- this.writePipe.write(lengthBuffer);
104
- }
105
- readNextMessage() {
106
- this.state = "read length";
107
- this.readBuffer(4, (lengthReadError, lengthBuffer) => {
108
- if (lengthReadError) {
109
- console.error(`Failed to communicate with worker (read length) ${lengthReadError}`);
110
- return;
111
- }
112
- this.state = "length read";
113
- const length = lengthBuffer.readInt32BE(0);
114
- this.state = "read message";
115
- this.readBuffer(length, (messageError, messageBuffer) => {
116
- if (messageError) {
117
- console.error(`Failed to communicate with worker (read message) ${messageError}`);
118
- return;
119
- }
120
- this.state = "message read";
121
- const messageString = messageBuffer.toString("utf-8");
122
- const message = JSON.parse(messageString, reviver);
123
- this.state = "process message";
124
- this.onWorkerMessage(message, (err) => {
125
- if (err) {
126
- console.error(`Failed to communicate with worker (process message) ${err}`);
127
- return;
128
- }
129
- this.state = "soon next";
130
- setImmediate(() => this.readNextMessage());
131
- });
132
- });
133
- });
134
- }
135
- onWorkerMessage(message, finalCallback) {
136
- const { type, id } = message;
137
- switch (type) {
138
- case "job": {
139
- const { data, error, result } = message;
140
- asyncMapSeries(
141
- data,
142
- (length, callback) => this.readBuffer(length, callback),
143
- (eachErr, buffers) => {
144
- const { callback: jobCallback } = this.jobs[id];
145
- const callback = (err, arg) => {
146
- if (jobCallback) {
147
- delete this.jobs[id];
148
- this.activeJobs -= 1;
149
- this.onJobDone();
150
- if (err) {
151
- jobCallback(err instanceof Error ? err : new Error(err), arg);
152
- } else {
153
- jobCallback(null, arg);
154
- }
155
- }
156
- finalCallback();
157
- };
158
- if (eachErr) {
159
- callback(eachErr);
160
- return;
161
- }
162
- let bufferPosition = 0;
163
- if (result.result) {
164
- result.result = result.result.map((r) => {
165
- if (r.buffer) {
166
- const buffer = buffers[bufferPosition];
167
- bufferPosition += 1;
168
- if (r.string) {
169
- return buffer.toString("utf-8");
170
- }
171
- return buffer;
172
- }
173
- return r.data;
174
- });
175
- }
176
- if (error) {
177
- callback(this.fromErrorObj(error), result);
178
- return;
179
- }
180
- callback(null, result);
181
- }
182
- );
183
- break;
184
- }
185
- case "loadModule": {
186
- const { request, questionId } = message;
187
- const { data } = this.jobs[id];
188
- data.loadModule(request, (error, source, sourceMap) => {
189
- this.writeJson({
190
- type: "result",
191
- id: questionId,
192
- error: error ? {
193
- message: error.message,
194
- details: error.details,
195
- missing: error.missing
196
- } : null,
197
- result: [
198
- source,
199
- sourceMap
200
- // TODO: Serialize module?
201
- // module,
202
- ]
203
- });
204
- });
205
- finalCallback();
206
- break;
207
- }
208
- case "resolve": {
209
- const { context, request, options, questionId } = message;
210
- const { data } = this.jobs[id];
211
- if (options) {
212
- data.getResolve(options)(context, request, (error, result) => {
213
- this.writeJson({
214
- type: "result",
215
- id: questionId,
216
- error: error ? {
217
- message: error.message,
218
- details: error.details,
219
- missing: error.missing
220
- } : null,
221
- result
222
- });
223
- });
224
- } else {
225
- data.resolve(context, request, (error, result) => {
226
- this.writeJson({
227
- type: "result",
228
- id: questionId,
229
- error: error ? {
230
- message: error.message,
231
- details: error.details,
232
- missing: error.missing
233
- } : null,
234
- result
235
- });
236
- });
237
- }
238
- finalCallback();
239
- break;
240
- }
241
- case "emitWarning": {
242
- const { data } = message;
243
- const { data: jobData } = this.jobs[id];
244
- jobData.emitWarning(this.fromErrorObj(data));
245
- finalCallback();
246
- break;
247
- }
248
- case "emitError": {
249
- const { data } = message;
250
- const { data: jobData } = this.jobs[id];
251
- jobData.emitError(this.fromErrorObj(data));
252
- finalCallback();
253
- break;
254
- }
255
- case "getLogger": {
256
- const { data } = message;
257
- const { data: jobData } = this.jobs[id];
258
- if (!Object.hasOwnProperty.call(jobData.loggers, data.name)) {
259
- jobData.loggers[data.name] = jobData.getLogger(data.name);
260
- }
261
- finalCallback();
262
- break;
263
- }
264
- case "logger": {
265
- const { data } = message;
266
- const { data: jobData } = this.jobs[id];
267
- jobData.loggers[data.name][data.severity](data.message);
268
- finalCallback();
269
- break;
270
- }
271
- default: {
272
- console.error(`Unexpected worker message ${type} in WorkerPool.`);
273
- finalCallback();
274
- break;
275
- }
276
- }
277
- }
278
- fromErrorObj(arg) {
279
- let obj;
280
- if (typeof arg === "string") {
281
- obj = { message: arg };
282
- } else {
283
- obj = arg;
284
- }
285
- return new WorkerError(obj, this.id);
286
- }
287
- readBuffer(length, callback) {
288
- readBuffer(this.readPipe, length, callback);
289
- }
290
- dispose() {
291
- if (!this.disposed) {
292
- this.disposed = true;
293
- this.ignoreStdOutAndErrFromWorker(this.worker.stdout, this.worker.stderr);
294
- this.writeEnd();
295
- }
296
- }
297
- }
298
- class WorkerPool {
299
- constructor(options) {
300
- this.options = options || {};
301
- this.numberOfWorkers = options.numberOfWorkers;
302
- this.poolTimeout = options.poolTimeout;
303
- this.workerNodeArgs = options.workerNodeArgs;
304
- this.workerParallelJobs = options.workerParallelJobs;
305
- this.workers = /* @__PURE__ */ new Set();
306
- this.activeJobs = 0;
307
- this.timeout = null;
308
- this.poolQueue = asyncQueue(this.distributeJob.bind(this), options.poolParallelJobs);
309
- this.terminated = false;
310
- this.setupLifeCycle();
311
- }
312
- isAbleToRun() {
313
- return !this.terminated;
314
- }
315
- terminate() {
316
- if (this.terminated) {
317
- return;
318
- }
319
- this.terminated = true;
320
- this.poolQueue.kill();
321
- this.disposeWorkers(true);
322
- }
323
- setupLifeCycle() {
324
- process.on("exit", () => {
325
- this.terminate();
326
- });
327
- }
328
- run(data, callback) {
329
- if (this.timeout) {
330
- clearTimeout(this.timeout);
331
- this.timeout = null;
332
- }
333
- this.activeJobs += 1;
334
- this.poolQueue.push(data, callback);
335
- }
336
- distributeJob(data, callback) {
337
- let bestWorker;
338
- for (const worker of this.workers) {
339
- if (!bestWorker || worker.activeJobs < bestWorker.activeJobs) {
340
- bestWorker = worker;
341
- }
342
- }
343
- if (bestWorker && (bestWorker.activeJobs === 0 || this.workers.size >= this.numberOfWorkers)) {
344
- bestWorker.run(data, callback);
345
- return;
346
- }
347
- const newWorker = this.createWorker();
348
- newWorker.run(data, callback);
349
- }
350
- createWorker() {
351
- const newWorker = new PoolWorker(
352
- {
353
- nodeArgs: this.workerNodeArgs,
354
- parallelJobs: this.workerParallelJobs
355
- },
356
- () => this.onJobDone()
357
- );
358
- this.workers.add(newWorker);
359
- return newWorker;
360
- }
361
- warmup(requires) {
362
- while (this.workers.size < this.numberOfWorkers) {
363
- this.createWorker().warmup(requires);
364
- }
365
- }
366
- onJobDone() {
367
- this.activeJobs -= 1;
368
- if (this.activeJobs === 0 && Number.isFinite(this.poolTimeout)) {
369
- this.timeout = setTimeout(() => this.disposeWorkers(), this.poolTimeout);
370
- }
371
- }
372
- disposeWorkers(fromTerminate) {
373
- if (!this.options.poolRespawn && !fromTerminate) {
374
- this.terminate();
375
- return;
376
- }
377
- if (this.activeJobs === 0 || fromTerminate) {
378
- for (const worker of this.workers) {
379
- worker.dispose();
380
- }
381
- this.workers.clear();
382
- }
383
- }
384
- }
385
- export {
386
- WorkerPool as default
387
- };
@@ -1,100 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var thread_loader_exports = {};
19
- __export(thread_loader_exports, {
20
- pitch: () => pitch,
21
- warmup: () => warmup
22
- });
23
- module.exports = __toCommonJS(thread_loader_exports);
24
- var import_workerPools = require("./workerPools.cjs");
25
- function pitch() {
26
- const options = this.getOptions();
27
- const workerPool = (0, import_workerPools.getPool)(options);
28
- if (!workerPool.isAbleToRun()) {
29
- return;
30
- }
31
- const callback = this.async();
32
- workerPool.run(
33
- {
34
- loaders: this.loaders.slice(this.loaderIndex + 1).map((l) => {
35
- return {
36
- loader: l.path,
37
- options: l.options,
38
- ident: l.ident
39
- };
40
- }),
41
- _compiler: {
42
- fsStartTime: this._compiler.fsStartTime,
43
- options: { plugins: [] }
44
- },
45
- _compilation: {
46
- outputOptions: {
47
- hashSalt: this._compilation.outputOptions.hashSalt,
48
- hashFunction: this._compilation.outputOptions.hashFunction,
49
- hashDigest: this._compilation.outputOptions.hashDigest,
50
- hashDigestLength: this._compilation.outputOptions.hashDigestLength
51
- },
52
- options: {
53
- devtool: this._compilation?.options?.devtool
54
- }
55
- },
56
- resourcePath: this.resourcePath,
57
- resource: this.resourcePath + (this.resourceQuery || ""),
58
- sourceMap: this.sourceMap,
59
- emitError: this.emitError,
60
- emitWarning: this.emitWarning,
61
- loadModule: this.loadModule,
62
- resolve: this.resolve,
63
- getResolve: this.getResolve,
64
- target: this.target,
65
- minimize: this.minimize,
66
- resourceQuery: this.resourceQuery,
67
- optionsContext: this.rootContext || this.options.context,
68
- rootContext: this.rootContext,
69
- getLogger: this.getLogger,
70
- loggers: {}
71
- },
72
- (err, r) => {
73
- if (r) {
74
- r.fileDependencies.forEach((d) => this.addDependency(d));
75
- r.contextDependencies.forEach((d) => this.addContextDependency(d));
76
- r.missingDependencies.forEach((d) => this.addMissingDependency(d));
77
- r.buildDependencies.forEach(
78
- (d) => (
79
- // Compatibility with webpack v4
80
- this.addBuildDependency ? this.addBuildDependency(d) : this.addDependency(d)
81
- )
82
- );
83
- }
84
- if (err) {
85
- callback(err);
86
- return;
87
- }
88
- callback(null, ...r.result);
89
- }
90
- );
91
- }
92
- function warmup(options, requires) {
93
- const workerPool = (0, import_workerPools.getPool)(options);
94
- workerPool.warmup(requires);
95
- }
96
- // Annotate the CommonJS export names for ESM import in node:
97
- 0 && (module.exports = {
98
- pitch,
99
- warmup
100
- });
@@ -1,85 +0,0 @@
1
- import { createRequire } from 'node:module';
2
- var require = createRequire(import.meta['url']);
3
-
4
- import path from "path";
5
- import { fileURLToPath } from "url";
6
- var getFilename = () => fileURLToPath(import.meta.url);
7
- var getDirname = () => path.dirname(getFilename());
8
- var __dirname = /* @__PURE__ */ getDirname();
9
- var __filename = /* @__PURE__ */ getFilename();
10
- import { getPool } from "./workerPools.js";
11
- function pitch() {
12
- const options = this.getOptions();
13
- const workerPool = getPool(options);
14
- if (!workerPool.isAbleToRun()) {
15
- return;
16
- }
17
- const callback = this.async();
18
- workerPool.run(
19
- {
20
- loaders: this.loaders.slice(this.loaderIndex + 1).map((l) => {
21
- return {
22
- loader: l.path,
23
- options: l.options,
24
- ident: l.ident
25
- };
26
- }),
27
- _compiler: {
28
- fsStartTime: this._compiler.fsStartTime,
29
- options: { plugins: [] }
30
- },
31
- _compilation: {
32
- outputOptions: {
33
- hashSalt: this._compilation.outputOptions.hashSalt,
34
- hashFunction: this._compilation.outputOptions.hashFunction,
35
- hashDigest: this._compilation.outputOptions.hashDigest,
36
- hashDigestLength: this._compilation.outputOptions.hashDigestLength
37
- },
38
- options: {
39
- devtool: this._compilation?.options?.devtool
40
- }
41
- },
42
- resourcePath: this.resourcePath,
43
- resource: this.resourcePath + (this.resourceQuery || ""),
44
- sourceMap: this.sourceMap,
45
- emitError: this.emitError,
46
- emitWarning: this.emitWarning,
47
- loadModule: this.loadModule,
48
- resolve: this.resolve,
49
- getResolve: this.getResolve,
50
- target: this.target,
51
- minimize: this.minimize,
52
- resourceQuery: this.resourceQuery,
53
- optionsContext: this.rootContext || this.options.context,
54
- rootContext: this.rootContext,
55
- getLogger: this.getLogger,
56
- loggers: {}
57
- },
58
- (err, r) => {
59
- if (r) {
60
- r.fileDependencies.forEach((d) => this.addDependency(d));
61
- r.contextDependencies.forEach((d) => this.addContextDependency(d));
62
- r.missingDependencies.forEach((d) => this.addMissingDependency(d));
63
- r.buildDependencies.forEach(
64
- (d) => (
65
- // Compatibility with webpack v4
66
- this.addBuildDependency ? this.addBuildDependency(d) : this.addDependency(d)
67
- )
68
- );
69
- }
70
- if (err) {
71
- callback(err);
72
- return;
73
- }
74
- callback(null, ...r.result);
75
- }
76
- );
77
- }
78
- function warmup(options, requires) {
79
- const workerPool = getPool(options);
80
- workerPool.warmup(requires);
81
- }
82
- export {
83
- pitch,
84
- warmup
85
- };
@@ -1,55 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var readBuffer_exports = {};
19
- __export(readBuffer_exports, {
20
- default: () => readBuffer
21
- });
22
- module.exports = __toCommonJS(readBuffer_exports);
23
- function readBuffer(pipe, length, callback) {
24
- if (length === 0) {
25
- callback(null, Buffer.alloc(0));
26
- return;
27
- }
28
- let remainingLength = length;
29
- const buffers = [];
30
- const readChunk = () => {
31
- const onChunk = (arg) => {
32
- let chunk = arg;
33
- let overflow;
34
- if (chunk.length > remainingLength) {
35
- overflow = chunk.slice(remainingLength);
36
- chunk = chunk.slice(0, remainingLength);
37
- remainingLength = 0;
38
- } else {
39
- remainingLength -= chunk.length;
40
- }
41
- buffers.push(chunk);
42
- if (remainingLength === 0) {
43
- pipe.removeListener("data", onChunk);
44
- pipe.pause();
45
- if (overflow) {
46
- pipe.unshift(overflow);
47
- }
48
- callback(null, Buffer.concat(buffers, length));
49
- }
50
- };
51
- pipe.on("data", onChunk);
52
- pipe.resume();
53
- };
54
- readChunk();
55
- }
@@ -1,45 +0,0 @@
1
- import { createRequire } from 'node:module';
2
- var require = createRequire(import.meta['url']);
3
-
4
- import path from "path";
5
- import { fileURLToPath } from "url";
6
- var getFilename = () => fileURLToPath(import.meta.url);
7
- var getDirname = () => path.dirname(getFilename());
8
- var __dirname = /* @__PURE__ */ getDirname();
9
- var __filename = /* @__PURE__ */ getFilename();
10
- function readBuffer(pipe, length, callback) {
11
- if (length === 0) {
12
- callback(null, Buffer.alloc(0));
13
- return;
14
- }
15
- let remainingLength = length;
16
- const buffers = [];
17
- const readChunk = () => {
18
- const onChunk = (arg) => {
19
- let chunk = arg;
20
- let overflow;
21
- if (chunk.length > remainingLength) {
22
- overflow = chunk.slice(remainingLength);
23
- chunk = chunk.slice(0, remainingLength);
24
- remainingLength = 0;
25
- } else {
26
- remainingLength -= chunk.length;
27
- }
28
- buffers.push(chunk);
29
- if (remainingLength === 0) {
30
- pipe.removeListener("data", onChunk);
31
- pipe.pause();
32
- if (overflow) {
33
- pipe.unshift(overflow);
34
- }
35
- callback(null, Buffer.concat(buffers, length));
36
- }
37
- };
38
- pipe.on("data", onChunk);
39
- pipe.resume();
40
- };
41
- readChunk();
42
- }
43
- export {
44
- readBuffer as default
45
- };