Options
All
  • Public
  • Public/Protected
  • All
Menu

Class URLResource

HTTPサーバなどで配信されるリソースを表現します。 ベースとなるリソースがサブリソースを持つようなリソースを想定したクラスです。

例としてhtmlの場合について説明します。 htmlファイルは画像やcssなど様々なサブリソースを持つことができます。 htmlファイルをベースとなるリソースと呼び、それ以外のファイルをサブリソースと呼びます。 サブリソースはベースとなるリソースからの相対パスで表現されることや、絶対パスで表現されることがあります。 また、htmlファイルには、別のhtmlファイルへのリンクが記述されることがあり、別のhtmlファイルはさらに画像やcssなどのファイルを持ちます。 このクラスは上記のような状況を表現することができます。

  • load はベースとなるリソースの内容を読み込みます。
  • loadSubResource は、ベースとなるリソースからの相対パスを指定してサブリソースの内容を読み込みます(絶対パスを指定すると指定したURLへ直接アクセスします)。
  • resolveResource は、別のhtmlファイルへのリンクをたどるような状況を表現する場合に利用します。相対パスや絶対パスを指定すると、新たな Resource を得ることができます。

下記に使用例を示します。

// https://.../test.html を起点とするリソースを定義します。
const resource = new URLResource("https://.../test.html");
// test.html の内容を読み込みます。

const html = await resource.load({ type: Resource.ResourceType.TEXT });
// test.html と同一パスにある画像を読み込みます。

const image = await resource.loadSubResource("image.png",
{ type: Resource.ResourceType.IMAGE });

// test.html からの相対パス(sub) にある 別のhtml(other.html) を起点とするリソースを定義します。
const otherResource = resource.resolveResource("sub/other.html");

// other.htmlの内容を読み込みます。
const otherHtml = await otherResource.load({ type: Resource.ResourceType.TEXT });

// other.htmlと同一パスにあるの画像を読み込みます。
const otherImage = await otherResource.loadSubResource("image.png",
{ type: Resource.ResourceType.IMAGE });

Hierarchy

Index

Constructors

Properties

_abort_ctrl: AbortController
_base_url: string
_transform: TransformCallback
_url: string

Accessors

  • get url(): string

Methods

  • cancel(): void
  • loadSubResourceSupported(): boolean
  • resolveResource(sub_url: string): Resource
  • resolveResourceSupported(): boolean