Options
All
  • Public
  • Public/Protected
  • All
Menu

new AFile(name, data, metadata)

This implements the same interface as FileAttachment, but works with supplied data in a variety of forms:

  • String—depending on the type requested, this may involve parsing or converting to an ArrayBuffer, Blob, or ReadableStream. options arguments to the various extractors can include {utf8: false} to use UTF16 rather than UTF8 encoding.
  • ArrayBuffer
  • ReadableStream
  • Blob
  • JSON-compatible objects
  • Arrays such as would be returned from .csv() or .tsv(). Non-arrays will be converted to strings and parsed.
  • A function. returning the value or a promise to the value. This is the most useful form, as it defers computation until needed. Except in the case of a ReadableStream, the result is cached. The function is called with the following arguments:
    • file: the AFile.
    • method: One of json, text. arrayBuffer, stream, url, csv, tsv. These indicate how the data will be used, allowing the function to choose how to represent it. the usual conversions will be applied as needed, however, so it may be safely ignored.
    • options: The options supplied to the method accessing the data.
  • Arbitrary data not described above, which can be retrieved unchanged via the .json() method
  • A Promise that resolves to any of the above.

metadata is either an object with metadata to be combined, or a string, which is interpreted as the contentType, as a shorthand when that is the only metadata being supplied.

All operations are asynchronous.

Hierarchy

  • AFile

Implements

Index

Constructors

constructor

  • new AFile(name: string, data: any, metadata?: Partial<Metadata>): AFile
  • Construct a new AFile

    Parameters

    • name: string

      Name of the file

    • data: any

      Data for the file. It will be converted as needed.

    • metadata: Partial<Metadata> = ...

      Optional metadata for the file.

    Returns AFile

Properties

Private #dataResult

#dataResult: any

Private #noCache

#noCache: boolean = false

[CACHED_METADATA]

[CACHED_METADATA]: Metadata

[METADATA]

[METADATA]: Metadata

[Symbol.toStringTag]

[Symbol.toStringTag]: "AFile"

Preserve the class name across minification.

content-type

content-type: string

data

data: any

name

name: string

Methods

arrayBuffer

  • arrayBuffer(opts?: DataOptions): Promise<ArrayBufferLike>
  • Return the data in an ArrayBuffer backed with a byte array.

    Parameters

    • opts: DataOptions = ...

      Options. The valid option is utf8, which defaults to true

    Returns Promise<ArrayBufferLike>

    A Promise which resolves to an array buffer with the data

blob

  • Return the data in the form of a Blob

    Parameters

    • opts: DataOptions = ...

      Options. The valid option is utf8, which defaults to true

    Returns Promise<Blob>

    A Promise that resolves to a Blob

csv

  • Interpret the data as CSV text. Uses D3's CSV/TSV parser.

    Parameters

    • opts: DataOptions = ...

      Options. The valid option is utf8, which defaults to true

    Returns Promise<any>

    A Promise which returns the data parsed as CSV

getData

  • Internal method.

    Parameters

    • type: DataFormat

      Method that is requesting the data, to handle any prepatory conversions needed

    • opts: DataOptions

      Any options passed to the original method

    Returns Promise<any>

    A Promise resolving to the data in the requested form.

json

  • Return the data as JSON (as a Promise)

    Parameters

    • opts: DataOptions = ...

      Options. The valid option is utf8, which defaults to true

    Returns Promise<any>

    A Promise that resolves to a JSON value.

stream

  • stream(opts?: DataOptions): Promise<ReadableStream<any>>

text

  • Return the data as a string.

    Parameters

    • opts: DataOptions = ...

      Options. The valid option is utf8, which defaults to true

    Returns Promise<string>

    A Promise that resolves to a text string.

tsv

  • Interpret the data as TSV text. Uses D3's CSV/TSV parser.

    Parameters

    • opts: DataOptions = ...

      Options. The valid option is utf8, which defaults to true

    Returns Promise<any>

    A Promise which returns the data parsed as TSV

url

  • Obtain Promise to a data URL with the data.

    Parameters

    • opts: DataOptions = ...

      Options. The valid option is utf8, which defaults to true

    Returns Promise<string>

    A Promise that resolves to a data URL with the data.

Generated using TypeDoc