diff options
author | Minteck <contact@minteck.org> | 2022-06-04 08:51:19 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-06-04 08:51:19 +0200 |
commit | b22f6770c8bd084d66950655203c61dd701b3d90 (patch) | |
tree | 873d7fb19584ec2709b95cc1ca05a1fc7cfd0fc4 /node_modules/got/source/progress.js | |
parent | 383285ecd5292bf9a825e05904955b937de84cc9 (diff) | |
download | equestriadb-b22f6770c8bd084d66950655203c61dd701b3d90.tar.gz equestriadb-b22f6770c8bd084d66950655203c61dd701b3d90.tar.bz2 equestriadb-b22f6770c8bd084d66950655203c61dd701b3d90.zip |
Remove node_modules
Diffstat (limited to 'node_modules/got/source/progress.js')
-rw-r--r-- | node_modules/got/source/progress.js | 96 |
1 files changed, 0 insertions, 96 deletions
diff --git a/node_modules/got/source/progress.js b/node_modules/got/source/progress.js deleted file mode 100644 index 666abcf..0000000 --- a/node_modules/got/source/progress.js +++ /dev/null @@ -1,96 +0,0 @@ -'use strict'; -const {Transform} = require('stream'); - -module.exports = { - download(response, emitter, downloadBodySize) { - let downloaded = 0; - - return new Transform({ - transform(chunk, encoding, callback) { - downloaded += chunk.length; - - const percent = downloadBodySize ? downloaded / downloadBodySize : 0; - - // Let `flush()` be responsible for emitting the last event - if (percent < 1) { - emitter.emit('downloadProgress', { - percent, - transferred: downloaded, - total: downloadBodySize - }); - } - - callback(null, chunk); - }, - - flush(callback) { - emitter.emit('downloadProgress', { - percent: 1, - transferred: downloaded, - total: downloadBodySize - }); - - callback(); - } - }); - }, - - upload(request, emitter, uploadBodySize) { - const uploadEventFrequency = 150; - let uploaded = 0; - let progressInterval; - - emitter.emit('uploadProgress', { - percent: 0, - transferred: 0, - total: uploadBodySize - }); - - request.once('error', () => { - clearInterval(progressInterval); - }); - - request.once('response', () => { - clearInterval(progressInterval); - - emitter.emit('uploadProgress', { - percent: 1, - transferred: uploaded, - total: uploadBodySize - }); - }); - - request.once('socket', socket => { - const onSocketConnect = () => { - progressInterval = setInterval(() => { - const lastUploaded = uploaded; - /* istanbul ignore next: see #490 (occurs randomly!) */ - const headersSize = request._header ? Buffer.byteLength(request._header) : 0; - uploaded = socket.bytesWritten - headersSize; - - // Don't emit events with unchanged progress and - // prevent last event from being emitted, because - // it's emitted when `response` is emitted - if (uploaded === lastUploaded || uploaded === uploadBodySize) { - return; - } - - emitter.emit('uploadProgress', { - percent: uploadBodySize ? uploaded / uploadBodySize : 0, - transferred: uploaded, - total: uploadBodySize - }); - }, uploadEventFrequency); - }; - - /* istanbul ignore next: hard to test */ - if (socket.connecting) { - socket.once('connect', onSocketConnect); - } else if (socket.writable) { - // The socket is being reused from pool, - // so the connect event will not be emitted - onSocketConnect(); - } - }); - } -}; |