URLから.gzファイルをダウンロードしてフォルダに保存したいだけです。可能であれば、サードパーティのライブラリなしでこれを実行したいと思います。これが私がこれまでに持っているものですが、それは空のファイルをダウンロードするだけです:
const fs = require('fs')
const https = require('https')
let file = fs.createWriteStream('./folder/filename.gz')
let request = https.get('https://someurl/somefile.gz', function(res) {
res.pipe(file)
})
これを試すことができます。nodesJSのHTTPモジュールを使用すると、他のファイルをダウンロードするのと同じように見えます。呼び出すときに、ダウンロードしたファイルの拡張子を忘れないinstead
でください。例を次に示します。
注:HTTPSリンクからダウンロードしようとしている場合は、代わりにHTTPSモジュールを使用してください。まったく同じですが
HTTP
、次のコードのすべてを次のように置き換えてください。HTTPS
const http = require('http');
const fs = require('fs');
//I added './' assuming that you want to download it where the server
//file is located, just change it to your desired path, followed by the
//filename and the EXTENSION
const file = fs.createWriteStream("./result.tar.gz");
const request = http.get("http://alpha.gnu.org/gnu/gzip/gzip-1.3.6.tar.gz", (response) => {
response.pipe(file);
});
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加