(length = 1024 * 1024, chunkSize = 10 * 1024, sleep = 50)
| 163 | export const nodeVersion = process.versions.node.split('.').map((v) => parseInt(v, 10)); |
| 164 | |
| 165 | export const generateReadable = (length = 1024 * 1024, chunkSize = 10 * 1024, sleep = 50) => { |
| 166 | return stream.Readable.from( |
| 167 | (async function* () { |
| 168 | let dataLength = 0; |
| 169 | |
| 170 | while (dataLength < length) { |
| 171 | const leftBytes = length - dataLength; |
| 172 | |
| 173 | const chunk = Buffer.alloc(leftBytes > chunkSize ? chunkSize : leftBytes); |
| 174 | |
| 175 | dataLength += chunk.length; |
| 176 | |
| 177 | yield chunk; |
| 178 | |
| 179 | if (sleep) { |
| 180 | await setTimeoutAsync(sleep); |
| 181 | } |
| 182 | } |
| 183 | })() |
| 184 | ); |
| 185 | }; |
| 186 | |
| 187 | export const makeReadableStream = (chunk = 'chunk', n = 10, timeout = 100) => { |
| 188 | return new ReadableStream( |
no test coverage detected