Options
All
  • Public
  • Public/Protected
  • All
Menu

Use the static methods in this class to create EpubOcfResourceProviders that are used for accessing the EPUB publications and their resources.

An file with a .epub extension is really a so called OCF container. The actual EPUB publication is contained in the OCF container. The OCF also specifies all encrypted resources within the container (see encryption.xml file). See EPUB Open Container Format (OCF): https://www.w3.org/publishing/epub3/epub-ocf.htm

Resources that are encrypted are decrypted using the DrmManager before it is returned. By default, the EpubOcfResourceProvider has support for the Resource Obfuscation Algorithm (https://www.w3.org/publishing/epub3/epub-ocf.html#sec-resource-obfuscation). In order to facilitate decryption for other algorithms you must provide the DrmManager with matching EncryptionMethod implementations.

See DrmManager for more information.

Hierarchy

  • EpubOcfResourceProvider

Implements

Index

Constructors

constructor

  • Used internally. Use the static methods on this class to create new EpubOcfResourceProvider instances.

    deprecated

    Use the static methods on this class to create new EpubOcfResourceProvider instances.

    Parameters

    • _backingResourceProvider: IResourceProvider
    • _mimetype: string
    • _drmManager: IDrmManager
    • _ocfHashSignature: string
    • _onDestroyed: () => void
        • (): void
        • Returns void

    Returns EpubOcfResourceProvider

Methods

acceptsUrl

  • acceptsUrl(url: string | URL): boolean
  • Returns true if this resource provider accepts the given URL. Whether the URL is accepted or not is implementation specific. It could for example be that the specified URL must be relative to the Base URL, or that the protocol used is http. Note that this is not an "exists" check, calling fetch() with the given URL can still fail even if this method returns true.

    If this method returns false, the fetch() method will fail with the specified URL.

    Parameters

    • url: string | URL

    Returns boolean

destroy

  • destroy(): void
  • Unloads all loaded EpubPublications, releasing any used resources.

    Note: If ReaderPublications have been loaded using Publications from this instance, You must call readingSystemEngine.unloadPublication() or readingSystemEngine.destroy() before calling this method.

    Returns void

disableBuiltInEncryptionMethods

  • disableBuiltInEncryptionMethods(): void

enableBuiltInEncryptionMethods

  • enableBuiltInEncryptionMethods(): void

fetch

  • Starts fetching a resource from this ResourceProvider. The returned Promise is resolved once a successful response is available.

    The response includes both the metadata for the resource and methods for reading the resource body.

    If a relative URL is specified, it will be resolved against the base URL of this ResourceProvider. If this ResourceProvider does not have a base URL, relative URLs will cause the returned Promise to be rejected.

    Contrary to the browser Fetch API, this method MUST reject the returned Promise if the request is non-successful, such as if the resource could not be found.

    The options parameter can be used to configure how the resource should be fetched. If the options parameter is not defined, the fetch is performed using the default values specified in IResourceRequestOptions.

    Parameters

    Returns Promise<IResourceResponse>

fetchMetadata

  • Fetches metadata about a resource using the specified URL.

    If a relative URL is specified, it will be resolved against the base URL of this ResourceProvider. If this ResourceProvider does not have a base URL, relative URLs will cause the returned Promise to be rejected.

    The options parameter can be used to configure the request. If the options parameter is not defined, the request is performed using the default values specified in IResourceRequestOptions.

    Parameters

    Returns Promise<IResourceMetadata>

getBaseUrl

  • getBaseUrl(): URL
  • Get the base URL for this ResourceProvider, if available. Relative URLs passed to fetch() or fetchMetadata() will be resolved using this base URL. The path component of the base URL SHOULD end with a forward slash.

    If null is returned, relative URLs cannot be used with fetch() or fetchMetadata().

    Returns URL

getDefaultPublication

getDrmManager

getMimeType

  • getMimeType(): string

getPublications

getResourceManifest

  • Get a list of ResourceMetadata items for all resources that can be fetched from this ResourceProvider instance. Returns null if this resource provider does not have a resource manifest.

    For example, the ZipResourceProvider has a central directory containing metadata about all resources within the zip file, and would therefore return a resource manifest.

    As another example, An HttpResourceProvider can probably not know about all available resources and should therefore return null.

    Returns IResourceMetadata[]

isDestroyed

  • isDestroyed(): boolean

isUrlSupportedByBrowser

  • Returns true if acceptsUrl() returns true for the URL, and the URL can be used by the browser directly without being fetched from the ResourceProvider. For example: If true is returned, the URL can be assigned to the src attributes of ,

    Returns false otherwise.

    Parameters

    Returns boolean

Static createFromArrayBuffer

  • Creates a new EpubOcfResourceProvider using the specified ArrayBuffer containing the .epub file data.

    Publication resources are extracted from the EPUB container using a WebWorker. If transfer is set to true, the ArrayBuffer is transferred to the WebWorker which will improve performance when loading the zip archive. See https://developer.mozilla.org/en-US/docs/Web/API/Transferable

    Encrypted resources within the EPUB container can be decrypted by configuring a DrmManager.

    If the EpubOcfResourceProvider is created successfully, you can use getDefaultPublication() method to get a Publication instance which can then be loaded into the ReadingSystemEngine using loadPublication().

    Parameters

    • data: ArrayBuffer

      The complete EPUB file as an ArrayBuffer.

    • transfer: boolean

      If true, transfers the ArrayBuffer to the WebWorker instance.

    • Optional drmManager: IDrmManager

      The DrmManager to use for this epub file. If omitted, a new DrmManager will be created with this instance.

    Returns Promise<IEpubOcfResourceProvider>

    Resolved with an IEpubOcfResourceProvider instance if the EPUB file was loaded successfully.

Static createFromBackingResourceProvider

  • Creates a new EpubOcfResourceProvider using the another ResourceProvider as source. In this case the specified backing ResourceProvider will be used to fetch publication resources instead of extracting them from an .epub file. This allows you for example to load resource form disk or from an HTTP endpoint where the EPUB container has already been extracted.

    Encrypted resources within the EPUB can be decrypted by configuring a DrmManager.

    If the EpubOcfResourceProvider is created successfully, you can use getDefaultPublication() method to get a Publication instance which can then be loaded into the ReadingSystemEngine using loadPublication().

    Parameters

    • backingResourceProvider: IResourceProvider

      The resource provider where the EPUB resources can be found.

    • ocfHashSignature: string

      Used for calculating the publications hashSignature and ultimately the default defaultLocatorUrl in EpubReaderPublication.

    • Optional drmManager: IDrmManager

      The DrmManager to use for this EPUB. If omitted, a new DrmManager will be created with this instance.

    • Optional onDestroyed: () => void

      Callback used when this resource provider is destroyed.

        • (): void
        • Returns void

    Returns Promise<IEpubOcfResourceProvider>

    Resolved with an EpubOcfResourceProvider instance if the EPUB was loaded successfully.

Static createFromBase64

  • Creates a new EpubOcfResourceProvider using the specified base64 encoded string containing the .epub file data.

    Encrypted resources within the EPUB container can be decrypted by configuring a DrmManager.

    If the EpubOcfResourceProvider is created successfully, you can use getDefaultPublication() method to get a Publication instance which can then be loaded into the ReadingSystemEngine using loadPublication().

    Parameters

    • data: string

      The complete EPUB file as a base64 encoded string.

    • Optional drmManager: IDrmManager

      The DrmManager to use for this epub file. If omitted, a new DrmManager will be created with this instance.

    Returns Promise<IEpubOcfResourceProvider>

    Resolved with an IEpubOcfResourceProvider instance if the EPUB file was loaded successfully.

Static createFromBlob

  • Creates a new EpubOcfResourceProvider using the specified Blob containing the .epub file data.

    Encrypted resources within the EPUB container can be decrypted by configuring a DrmManager.

    If the EpubOcfResourceProvider is created successfully, you can use getDefaultPublication() method to get a Publication instance which can then be loaded into the ReadingSystemEngine using loadPublication().

    Parameters

    • data: Blob

      The complete EPUB file as a Blob.

    • Optional drmManager: IDrmManager

      The DrmManager to use for this epub file. If omitted, a new DrmManager will be created with this instance.

    Returns Promise<IEpubOcfResourceProvider>

    Resolved with an IEpubOcfResourceProvider instance if the EPUB file was loaded successfully.

Static createFromRandomAccessDataSource

  • Creates a new EpubOcfResourceProvider using the specified IRandomAccessDataSource containing the .epub file data.

    When loading an EPUB container using this method, the EPUB file is streamed in chunks from IRandomAccessDataSource. Using this method, the framework will download only the requested portions of the publication, thus minimizing load times and data usage.

    Publication resources are extracted from the EPUB container using a WebWorker. If options.transferBuffers is set to true, the resulting ArrayBuffers from calling IRandomAccessDataSource.fetchChunk() are transferred to the WebWorker. This will improve performance when extracting resource data from the EPUB. See https://developer.mozilla.org/en-US/docs/Web/API/Transferable

    Encrypted resources within the EPUB container can be decrypted by configuring a DrmManager.

    If the EpubOcfResourceProvider is created successfully, you can use getDefaultPublication() method to get a Publication instance which can then be loaded into the ReadingSystemEngine using loadPublication().

    Parameters

    • dataSource: IRandomAccessDataSource

      The instance where chunks of zip data can be fetched.

    • Optional drmManager: IDrmManager

      The DrmManager to use for this epub file. If omitted, a new DrmManager will be created with this instance.

    • Optional options: Partial<IZipResourceProviderOptions>

      Configures how the underlying ZipResourceProvider will fetch data from dataSource.

    Returns Promise<IEpubOcfResourceProvider>

Generated using TypeDoc