{{pkg.description}}
{{meta.status}}
{{repo.supportPackages}}
{{repo.relatedPackages}}
{{meta.blogPosts}}
{{pkg.install}}
{{pkg.size}}
{{pkg.deps}}
{{repo.examples}}
{{pkg.docs}}
import { download } from "@thi.ng/dl-asset";
const src = "Hellö wörld!";
// mime type derived from file extension (.txt)
download("hello.txt", src, {
utf8: true,
expire: 1000
});
// with explicit MIME type string
download("hello.txt", src, {
mime: "text/plain",
utf8: true,
expire: 1000
});
...or using MIME type preset from @thi.ng/mime.
import { preferredType } from "@thi.ng/mime";
downloadWithMime("hello.txt", src, {
// here mandatory to provide MIME type
mime: preferredType("txt"), // text/plain
utf8: true,
expire: 1000
});
Since v2.1.0, HTML canvas downloads can be simplified using
downloadCanvas()
:
import { downloadCanvas } from "@thi.ng/dl-asset";
// download as PNG (default)
downloadCanvas(canvas, "file-name-without-ext");
// download as JPG or WebP with given quality
downloadCanvas(canvas, "file-name-without-ext", "jpeg", 0.9);
downloadCanvas(canvas, "file-name-without-ext", "webp", 0.9);