@tokenizer/range
Advanced tools
Comparing version 0.9.0 to 0.10.0
@@ -21,3 +21,7 @@ import { RangeRequestTokenizer, roundRange } from './range-request-tokenizer.js'; | ||
} | ||
return new RangeRequestTokenizer(this.rangeRequestClient, headRequestInfo, this.config.minimumChunkSize); | ||
return new RangeRequestTokenizer(this.rangeRequestClient, { | ||
fileInfo: headRequestInfo, | ||
minimumChunkSize: this.config.minimumChunkSize, | ||
abortSignal: config?.abortSignal | ||
}); | ||
} | ||
@@ -24,0 +28,0 @@ /** |
import { AbstractTokenizer, type IReadChunkOptions } from 'strtok3'; | ||
import type { IContentRangeType, IHeadRequestInfo, IRangeRequestClient } from './types.js'; | ||
interface IRangeRequestTokenizerOptions { | ||
fileInfo: IHeadRequestInfo; | ||
minimumChunkSize: number; | ||
abortSignal?: AbortSignal; | ||
} | ||
/** | ||
@@ -12,6 +17,5 @@ * RangeRequestTokenizer is tokenizer which is an adapter for range-request clients. | ||
private rangeRequestClient; | ||
private minimumChunkSize; | ||
private abortController?; | ||
private options; | ||
private _fileData; | ||
constructor(rangeRequestClient: IRangeRequestClient, fileInfo: IHeadRequestInfo, minimumChunkSize: number, abortController?: AbortController | undefined); | ||
constructor(rangeRequestClient: IRangeRequestClient, options: IRangeRequestTokenizerOptions); | ||
/** | ||
@@ -46,1 +50,2 @@ * Read portion from stream | ||
export declare function parseContentRange(contentRange: string): IContentRangeType; | ||
export {}; |
@@ -13,11 +13,13 @@ import { AbstractTokenizer } from 'strtok3'; | ||
export class RangeRequestTokenizer extends AbstractTokenizer { | ||
constructor(rangeRequestClient, fileInfo, minimumChunkSize, abortController) { | ||
super({ fileInfo }); | ||
constructor(rangeRequestClient, options) { | ||
super({ fileInfo: options.fileInfo }); | ||
this.rangeRequestClient = rangeRequestClient; | ||
this.minimumChunkSize = minimumChunkSize; | ||
this.abortController = abortController; | ||
if (Number.isNaN(minimumChunkSize)) { | ||
this.options = options; | ||
if (Number.isNaN(options.minimumChunkSize)) { | ||
throw new Error('minimumChunkSize must be a number'); | ||
} | ||
this._fileData = new ChunkedFileData(); | ||
this.options.abortSignal?.addEventListener('abort', () => { | ||
this.abort(); | ||
}); | ||
} | ||
@@ -89,3 +91,3 @@ /** | ||
async abort() { | ||
this.abortController?.abort(); | ||
this.rangeRequestClient.abort(); | ||
} | ||
@@ -106,3 +108,3 @@ async loadRange(range) { | ||
// make a difference. | ||
range = roundRange(range, this.minimumChunkSize); | ||
range = roundRange(range, this.options.minimumChunkSize); | ||
// Upper range should not be greater than max file size | ||
@@ -109,0 +111,0 @@ range[1] = Math.min(this.fileInfo.size - 1, range[1]); |
import type { IFileInfo } from 'strtok3'; | ||
export interface IRangeRequestConfig { | ||
abortController?: AbortController; | ||
abortSignal?: AbortSignal; | ||
timeoutInSec?: number; | ||
@@ -52,2 +52,6 @@ avoidHeadRequests?: boolean; | ||
getResponse(method: string, range?: [number, number]): Promise<IRangeRequestResponse>; | ||
/** | ||
* Abort pending asynchronous operations | ||
*/ | ||
abort(): void; | ||
} |
{ | ||
"name": "@tokenizer/range", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"description": "Range-request tokenizer adapter", | ||
@@ -5,0 +5,0 @@ "type": "module", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27589
528