Options
All
  • Public
  • Public/Protected
  • All
Menu

@thi.ng/dl-asset

Index

Functions

Const download

  • download(name: string, src: string | TypedArray | ArrayBuffer | Blob, opts?: Partial<DownloadOpts>): void
  • Similar to (and wrapping) downloadWithMime with additional automatic MIME type detection. If no MIME type is given, attempts to derive it from the given filename's extension (e.g. .svg) and if that fails, falls back to default value.

    Parameters

    • name: string
    • src: string | TypedArray | ArrayBuffer | Blob
    • opts: Partial<DownloadOpts> = ...

    Returns void

Const downloadWithMime

  • downloadWithMime(name: string, src: string | TypedArray | ArrayBuffer | Blob, opts: Partial<DownloadOpts> & { mime: string }): void
  • Triggers download of given src blob (or typed array or string) as local file with filename name. MIME type option MUST be given. UTF-8 text encoding and URL expiry can be defined via the optional opts config object. See DownloadOpts for details & defaults. Use download if auto-detection of MIME type is required.

    remarks

    If src is not a blob already, it will be wrapped as such automatically. The mime option is only used for that wrapping purpose. The utf8 option is only used if src is a string and will trigger UTF-8 encoding of src.

    The function creates an object URL for download, which auto-expires again after expire millseconds (default: 10000) to free up memory. The URL won't be expired if expire <= 0.

    Parameters

    • name: string
    • src: string | TypedArray | ArrayBuffer | Blob
    • opts: Partial<DownloadOpts> & { mime: string }

    Returns void

Generated using TypeDoc