add snarf.ts
This commit is contained in:
parent
447a54e516
commit
13d67c363e
14
snarf.ts
Normal file
14
snarf.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { readerFromStreamReader } from "https://deno.land/std/io/mod.ts";
|
||||
import { basename, dirname } from "https://deno.land/std/path/mod.ts";
|
||||
|
||||
export async function snarf(url: Request | string, init?: RequestInit, fn?: string): Promise<void> {
|
||||
var outf= fn ?? basename(typeof url === "string" ? url : url.url)
|
||||
res= await fetch(url, init);
|
||||
sr= res.body?.getReader();
|
||||
if(sr !== null && sr !== void 0) {
|
||||
var r=readerFromStreamReader(sr);
|
||||
var f=Deno.open(outf, {create:true,write:true})
|
||||
await Deno.copy(r,f)
|
||||
f.close()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user