Class DefaultStorage<Context>

A sensible (if not optimized) default storage implementation for the RangeFinder class.

Available features:

  • LRU-like limiting behavior.
  • TTL for stored streams.

RangeFinder for details.

Type Parameters

  • Context = void

Implements

Constructors

Properties

Methods

Constructors

  • Create a new storage.

    Type Parameters

    • Context = void

    Parameters

    • createStream: ((context: Context) => Readable)

      a factory function for creating new streams. Note that the stream is fully managed while stored.

        • (context): Readable
        • Parameters

          Returns Readable

    • options: Readonly<{
          maxSize: number;
          ttl?: number;
          cacheKey?(context: Context): unknown;
      }>

      configuration options.

    Returns DefaultStorage<Context>

    DefaultStorageOptions for configuration details.

Properties

createStream: ((context: Context) => Readable)

a factory function for creating new streams. Note that the stream is fully managed while stored.

Methods

  • Get a cache key from a given Context. Useful when context object is rich and not unique, but a sub-property of it (e.g. context.path) uniquely represents the cached value.

    Parameters

    • context: Context

      Typically a file path, but could be an arbitrary object.

    Returns unknown

    An arbitrary string or object to be used as a key for an Map

  • Put managed stream into the storage.

    Parameters

    • entry: Readonly<{
          offset: number;
          stream: Readable;
      }>

      Entry to be stored.

    • context: Context

      Context reference.

    Returns void

  • Remove managed stream from the storage. Called when managed stream gets destroyed.

    Parameters

    • entry: Readonly<{
          offset: number;
          stream: Readable;
      }>

      Entry to be removed.

    • context: Context

      A context reference that was provided to put().

    Returns void

  • Take stored stream out of the storage (and remove it). The returned entry MUST have an entry.offset less or equal to startOffset.

    Ideally, it should be as close as possible to startOffset.

    Parameters

    • startOffset: number

      Starting offset into the stream.

    • context: Context

      A context reference that was provided to put().

    Returns undefined | Readonly<{
        offset: number;
        stream: Readable;
    }>

    Stored entry or undefined.