Skip to content

Commit

Permalink
Implement, type and document means to setCacheSize through an xget in…
Browse files Browse the repository at this point in the history
…stance
  • Loading branch information
miraclx committed Jul 2, 2020
1 parent 4061cb0 commit e8d9155
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ Returns the hash algorithm if any is in use.

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.

### xget.setCacheCapacity()

- `size`: <[number][]>
- Returns: <[XGETStream](#xgetstream)>

Set maximum capacity for internal cache.

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

- `tag`: &lt;[string][]&gt;
Expand Down
4 changes: 4 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ function xonstructor(url, opts) {
return hash;
};
this.getHashAlgorithm = () => store.hash.algorithm;
this.setCacheSize = size => {
if (XGET_CHECK_VAR(size, 'size', 'number', false)) store.cache.setCapacity(size);
return this;
};
this.use = (tag, fn) => {
if (store.loaded) throw new XgetException('failed to attach use middleware: content loaded');
XGET_CHECK_VAR(fn, 'fn', 'function');
Expand Down
1 change: 1 addition & 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;
setCacheSize(size: number): this;
setHeadHandler(fn: HeadHandler): boolean;
use(tag: string, fn: UseMiddlewareFn): this;
with(tag: string, fn: WithMiddlewareFn): this;
Expand Down

0 comments on commit e8d9155

Please sign in to comment.