Files
DefinitelyTyped/types/download/download-tests.ts
Dimitri B 8b99f540f7 🤖 Merge PR #63567 [got] Remove types by @BendingBender
* [got] Remove types

* Change Bluebird dep from 2->3

This isn't strictly accurate, but makes the types work out, since
p-cancelable's types, a transitive dependency of got, have a
Promise.cancel return type that conflicts with bluebird@2's.

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2022-12-15 08:37:27 -08:00

41 lines
1.4 KiB
TypeScript

import * as fs from "fs";
import download = require("download");
// test type exports
type DownloadOptions = download.DownloadOptions;
download("http://unicorn.com/foo.jpg"); // $ExpectType Promise<Buffer> & GotEmitter & Duplex
download("http://unicorn.com/foo.jpg", "dist"); // $ExpectType Promise<Buffer> & GotEmitter & Duplex
download("http://unicorn.com/foo.jpg", "dist", { extract: true }); // $ExpectType Promise<Buffer> & GotEmitter & Duplex
download("http://unicorn.com/foo.jpg", "dist", { filename: "foo" }); // $ExpectType Promise<Buffer> & GotEmitter & Duplex
download("http://unicorn.com/foo.jpg", { extract: true }); // $ExpectType Promise<Buffer> & GotEmitter & Duplex
download("http://unicorn.com/foo.jpg", { filename: "foo" }); // $ExpectType Promise<Buffer> & GotEmitter & Duplex
download("http://unicorn.com/foo.jpg").then(data => {
fs.writeFileSync("dist/foo.jpg", data);
});
download("unicorn.com/foo.jpg").pipe(fs.createWriteStream("dist/foo.jpg"));
// Got options
download("unicorn.com/foo.jpg", "dest", {
decompress: true,
encoding: "utf8",
followRedirect: true,
query: "",
timeout: {
connect: 20,
request: 20,
socket: 20,
},
useElectronNet: true,
});
// Decompress options
download("unicorn.com/foo.jpg", "dest", {
filter: file => true,
map: file => file,
plugins: [],
strip: 1,
});