This module provides different methods to load data into Discovery.js applications. The public API includes the following functions:
loadDataFromStream(stream, options)
loadDataFromEvent(event, options)
loadDataFromFile(file, options)
loadDataFromUrl(url, options)
loadDataFromPush(options)
Each function accepts an options
parameter, which is an object containing various settings that affect the behavior of the loader.
The following options are available for all the loadDataFrom*
functions:
size
(Number): An optional number representing the total size of the data being loaded (in bytes). If provided, the progress reported by the loader will be more accurate.resource
(Object): An optional object containing meta information about the loading resource, such as its name and creation timestamp. See theresource
structure section for details.
In addition to the Common options, the loadDataFromUrl
function accepts the following additional options:
isResponseOk
(Function): An optional function that takes aresponse
object as an argument and returns a boolean value indicating whether the response is considered successful. Defaults to(response) => response.ok
.getContentSize
(Function): An optional function that takes aresponse
object as an argument and returns the size of the content being loaded. Defaults to a function that returns the value of thex-file-size
header if present, or thecontent-length
header if the URL is of the same origin and there is nocontent-encoding
header.getContentCreatedAt
(Function): An optional function that takes aresponse
object as an argument and returns the created at timestamp of the content being loaded. Defaults to a function that returns the value of thex-file-created-at
header if present, or thelast-modified
header otherwise.fetch
(Object): An optional object containing additional options for thefetch
function, such asmethod
,headers
,mode
, etc.
The resource
object can contain the following properties (all are optional):
type
(string): Any stringname
(string): Any stringencoding
(string):json
orjsonxl/snapshot9
, set by a loader depending on encodingsize
(number): A size of the resource in bytes or UTF8 charsencodedSize
(number): An encoded size of the resource in case encoding is used (gzip or similar), i.e. the size before decoding or transfered sizecreatedAt
(Date | string | number): An optional timestamp indicating when the data was created. Can be aDate
object, a string in a format parseable by theDate.parse()
method, or a number representing the number of milliseconds since the Unix epoch (January 1, 1970, 00:00:00 UTC).
Example:
{
type: 'url',
name: 'http://example.com/data.json'
encoding: 'json',
createdAt: '2023-04-01T12:00:00Z',
}