File size: 3,200 Bytes
c592d77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
0 && (module.exports = {
    createNodeStreamFromChunks: null,
    createNodeStreamWithLateRelease: null
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: all[name]
    });
}
_export(exports, {
    createNodeStreamFromChunks: function() {
        return createNodeStreamFromChunks;
    },
    createNodeStreamWithLateRelease: function() {
        return createNodeStreamWithLateRelease;
    }
});
const _invarianterror = require("../../../shared/lib/invariant-error");
function createNodeStreamWithLateRelease(partialChunks, allChunks, releaseSignal) {
    if (process.env.NEXT_RUNTIME === 'edge') {
        throw Object.defineProperty(new _invarianterror.InvariantError('createNodeStreamWithLateRelease cannot be used in the edge runtime'), "__NEXT_ERROR_CODE", {
            value: "E993",
            enumerable: false,
            configurable: true
        });
    } else {
        const { Readable } = require('node:stream');
        let nextIndex = 0;
        const readable = new Readable({
            read () {
                while(nextIndex < partialChunks.length){
                    this.push(partialChunks[nextIndex]);
                    nextIndex++;
                }
            }
        });
        releaseSignal.addEventListener('abort', ()=>{
            // Flush any remaining chunks from the original set
            while(nextIndex < partialChunks.length){
                readable.push(partialChunks[nextIndex]);
                nextIndex++;
            }
            // Flush all chunks since we're now aborted and can't schedule
            // any new work but these chunks might unblock debugInfo
            while(nextIndex < allChunks.length){
                readable.push(allChunks[nextIndex]);
                nextIndex++;
            }
            setImmediate(()=>{
                readable.push(null);
            });
        }, {
            once: true
        });
        return readable;
    }
}
function createNodeStreamFromChunks(chunks, signal) {
    if (process.env.NEXT_RUNTIME === 'edge') {
        throw Object.defineProperty(new _invarianterror.InvariantError('createNodeStreamFromChunks cannot be used in the edge runtime'), "__NEXT_ERROR_CODE", {
            value: "E945",
            enumerable: false,
            configurable: true
        });
    } else {
        const { Readable } = require('node:stream');
        // If there's a signal, delay closing until it fires
        if (signal) {
            signal.addEventListener('abort', ()=>{
                readable.push(null);
            }, {
                once: true
            });
        }
        let nextIndex = 0;
        const readable = new Readable({
            read () {
                while(nextIndex < chunks.length){
                    this.push(chunks[nextIndex]);
                    nextIndex++;
                }
                if (!signal) {
                    this.push(null);
                }
            }
        });
        return readable;
    }
}

//# sourceMappingURL=stream-utils.js.map