LeafResource represents any Resource without links (e.g. fonts, images, videos).

It basically contains a Blob and a URL, and does nothing special.

Hierarchy

Constructors

Accessors

  • get url(): `${string}:${string}`
  • URL of the resource.

    Returns `${string}:${string}`

  • get blob(): Blob
  • A Blob with the current resource content.

    Returns Blob

  • An empty list. A leaf resource has zero links by definition.

    Returns Link[] & []

  • An array of Links (a subset of links), containing only subresource links, and for whose subresourceType a Resource subclass exists. That is, those links that fromLink accepts.

    Returns SubresourceLink[]

Methods

  • Create a Resource from a Blob and a URL, and a subresource type.

    Note that the URL is not resolved (see fromLink for that), but is used to interpret any relative links that the resource may contain.

    Currently, the subresourceType is mandatory, and determines what subclass of Resource is instantiated (in freeze-dry, this method is only used for subresources, so the expected type is always known). The Blob’s MIME type is ignored.

    Returns

    An instance of a subclass of Resource matching the given subresource type.

    Parameters

    • __namedParameters: { blob: Blob; url: `${string}:${string}` }
      • blob: Blob
      • url: `${string}:${string}`

    Returns Promise<LeafResource>

  • ‘Dry’ the resource, i.e. make it static and context-free.

    Returns void

  • Make ‘outward’ links absolute, and ‘within-document’ links relative (e.g. href="#top").

    Returns void

  • Fetch the resource a given link points to, and return it as a Resource.

    This method does not modify the given link; the caller can store the created Resource in link.resource, to grow a tree of links and resources.

    Example

    link.resource = await Resource.fromLink(link)
    

    Returns

    The newly created Resource.

    Parameters

    • link: SubresourceLink

      The link pointing to the resource.

    • config: GlobalConfig & { fetchResource?: Fetchy; signal?: AbortSignal } = {}

      Optional environment configuration.

    Returns Promise<Resource>

  • Determine the Resource subclass to use for the given subresource type.

    Returns

    The appropriate Resource subclass, or undefined if the type is not supported.

    Parameters

    • subresourceType: undefined | SubresourceType

      The type of subresource expected by the parent resource, e.g. 'image' or 'style'. Note this is not the same as its MIME type.

    Returns undefined | ResourceFactory