Skip to content

Instantly share code, notes, and snippets.

@mirismaili
Last active February 14, 2024 10:26
Show Gist options
  • Save mirismaili/4de8575ff0697a433dfb865e0cdccba1 to your computer and use it in GitHub Desktop.
Save mirismaili/4de8575ff0697a433dfb865e0cdccba1 to your computer and use it in GitHub Desktop.
Fast download>--pipe-->extract using node.js. For `tar` and `.tar.gz` files
/**
* Download and extract `.tar.gz` file using node.js
*
* Created on 1400/2/7 (2021/4/27).
* @author {@link https://mirismaili.github.io S. Mahdi Mir-Ismaili}
*/
import http from 'http'
import https from 'https'
import tar from 'tar'
const url = new URL(process.argv[2]) // 'https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.10.2-97d11b01.tar.gz'
const agent = url.protocol === 'https:' ? https : http
// noinspection JSCheckFunctionSignatures
agent.get(url, res => res.pipe(tar.x()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment