Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
miraclx committed Jun 23, 2020
1 parent 6ff3caa commit 9f7ad6b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ With 10 simultaneous downloads. Retrying each one to a max of 10.
- `hash`: <[string][]> Hash algorithm to use to create a [crypto.Hash][] instance computing the stream hash.
- `use`: <[object][]> Key-value pairs of middlewares with which to pipe the response object through. keys are [strings][string], values are [Transformer generating functions](#usemiddlewarefn) (Alternatively, use the [xget.use()](#xgetuse) method).
- `with`: <[object][]> Key-value pairs of middlewares with which to pipe the dataslice object through. keys are [strings][string], values are [functions][function] whose return values are accessible within the [store](#storestack). (Alternatively, use the [xget.with()](#xgetwith) method).
- `headHandler`: <[HeadHandler](#headhandler)> An interceptor for the initial HEAD data, useful for programmatically defining a range offset;

### <a id='xgetstore'></a> xget.store: [`Map`][map]

Expand Down Expand Up @@ -195,6 +196,13 @@ This ensures you can get a hash of an instancce of the data even while still str

Returns the hash algorithm if any is in use.

### xget.setHeadHandler()

- `fn`: &lt;[HeadHandler](#headhandler)&gt; Handler to be set.
- Returns: &lt;[boolean][]&gt; Whether or not the handler was successfully set.

Sets an interceptor for the initial HEAD data, useful for programmatically defining a range offset. Returns `false` if the request has already been loaded, `true` if successfully set.

### <a id='xgetuse'></a> xget.use(tag, handler)

- `tag`: &lt;[string][]&gt;
Expand Down Expand Up @@ -255,13 +263,24 @@ xget(URL)

```

### <a id='headhandler'></a> HeadHandler: [`function`][function]

- `props`: &lt;[object][]&gt;
- `headers`: &lt;[IncomingHttpHeaders][incominghttpheaders]&gt; HEAD headers from the URL.
- `acceptsRanges`: &lt;[boolean][]&gt; Whether or not the URL resource accepts byte ranges.
- Returns: &lt;[number] | void&gt; An offset to begin streaming from. Analogous to `.start`. If void, defaults to `.start` or `0`;

An interceptor for the initial HEAD data, useful for programmatically defining a range offset.

### <a id='loaddata'></a> LoadData: [`Object`][object]

- `url`: &lt;[string][]&gt; The URL specified.
- `size`: &lt;[number][]&gt; Finite number returned if server responds appropriately, else `Infinity`.
- `start`: &lt;[number][]&gt; Sticks to specification if server allows chunking via `content-ranges` else, resets to `0`.
- `chunkable`: &lt;[number][]&gt; Whether or not the URL feed can be chunked, supporting simultaneous connections.
- `totalSize`: &lt;[number]&gt; Actual size of the resource without an offset.
- `chunkStack`: &lt;[ChunkLoadInstance](#chunkloadinstance)[]&gt; The chunkstack array.
- `headers`: &lt;[IncomingHttpHeaders][incominghttpheaders]&gt; The recieved array.

### <a id='chunkloadinstance'></a> ChunkLoadInstance: [`Object`][object]

Expand Down
4 changes: 4 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ declare namespace xget {
getHash(): Buffer;
getHash(encoding: string): string;
getHashAlgorithm(): string;
setHeadHandler(fn: HeadHandler): boolean;
use(tag: string, fn: UseMiddlewareFn): this;
with(tag: string, fn: WithMiddlewareFn): this;
getErrContext(err: Error): { raw: Error, tag: string, source: 'xget:with' | 'xget:use' }
Expand All @@ -53,6 +54,7 @@ declare namespace xget {
chunks: number;
retries: number;
timeout: number;
headHandler: HeadHandler;
}

interface ChunkLoadInstance {
Expand All @@ -74,12 +76,14 @@ declare namespace xget {
size: number;
start: number;
chunkable: boolean;
totalSize: number;
chunkStack: ChunkLoadInstance[];
headers: IncomingHttpHeaders;
}

type MiddlewareStore = Map<string, any>;

type HeadHandler = (props: {headers: IncomingHttpHeaders, acceptsRanges: boolean}) => number | void;
type UseMiddlewareFn = (dataSlice: ChunkLoadInstance, store: MiddlewareStore) => NodeJS.ReadWriteStream;
type WithMiddlewareFn = (loadData: LoadDataSlice) => any;

Expand Down

0 comments on commit 9f7ad6b

Please sign in to comment.