Last active
May 15, 2020 16:07
-
-
Save iambenkay/bec2d0009a601ef519f0816348cfdc1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const net = require("net"), fs = require("fs"), remote_server = process.argv[2]; | |
let socket; | |
socket = remote_server ? net.connect(8000, remote_server) : net.connect(8000); | |
let ostream = fs.createWriteStream("./receiver/SC-02.pdf"); | |
let date = new Date(), size = 0, elapsed; | |
socket.on('data', chunk => { | |
size += chunk.length; | |
elapsed = new Date() - date; | |
socket.write(`\r${(size / (1024 * 1024)).toFixed(2)} MB of data was sent. Total elapsed time is ${elapsed / 1000} s`) | |
process.stdout.write(`\r${(size / (1024 * 1024)).toFixed(2)} MB of data was sent. Total elapsed time is ${elapsed / 1000} s`); | |
ostream.write(chunk); | |
}); | |
socket.on("end", () => { | |
console.log(`\nFinished getting file. speed was: ${((size / (1024 * 1024)) / (elapsed / 1000)).toFixed(2)} MB/s`); | |
process.exit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment