Move partial of req.range documents to range-parser

This commit is contained in:
Satana Charuwichitratana
2018-06-04 15:04:46 +07:00
parent 7c501b22e6
commit 5fbc378a2f
2 changed files with 18 additions and 13 deletions
+7 -13
View File
@@ -23,7 +23,7 @@ declare global {
import * as http from "http";
import { EventEmitter } from "events";
import { Options as RangeParserOptions } from "range-parser";
import { Options as RangeParserOptions, Result as RangeParserResult, Ranges as RangeParserRanges } from "range-parser";
export interface NextFunction {
// tslint:disable-next-line callable-types (In ts2.1 it thinks the type alias has no call signatures)
@@ -175,7 +175,7 @@ export interface CookieOptions {
export interface ByteRange { start: number; end: number; }
export interface RequestRanges extends Array<ByteRange> { type: string; }
export interface RequestRanges extends RangeParserRanges { }
export type Errback = (err: Error) => void;
@@ -287,22 +287,16 @@ export interface Request extends http.IncomingMessage, Express.Request {
* Parse Range header field, capping to the given `size`.
*
* Unspecified ranges such as "0-" require knowledge of your resource length. In
* the case of a byte range this is of course the total number of bytes. If the
* Range header field is not given `undefined` is returned, `-1` when unsatisfiable,
* and `-2` when syntactically invalid.
*
* When ranges are returned, the array has a "type" property which is the type of
* range that is required (most commonly, "bytes"). Each array element is an object
* with a "start" and "end" property for the portion of the range.
*
* The "combine" option can be set to `true` and overlapping & adjacent ranges
* will be combined into a single range.
* the case of a byte range this is of course the total number of bytes.
* If the Range header field is not given `undefined` is returned.
* If the Range header field is given, return value is a result of range-parser.
* See more ./types/range-parser/index.d.ts
*
* NOTE: remember that ranges are inclusive, so for example "Range: users=0-3"
* should respond with 4 users when available, not 3.
*
*/
range(size: number, options?: RangeParserOptions): RequestRanges | undefined | -1 | -2;
range(size: number, options?: RangeParserOptions): RangeParserRanges | RangeParserResult | undefined;
/**
* Return an array of Accepted media types
+11
View File
@@ -3,6 +3,13 @@
// Definitions by: Tomek Łaziuk <https://github.com/tlaziuk>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* Returns `-1` when unsatisfiable and `-2` when syntactically invalid.
*
* When ranges are returned, the array has a "type" property which is the type of
* range that is required (most commonly, "bytes"). Each array element is an object
* with a "start" and "end" property for the portion of the range.
*/
declare function RangeParser(size: number, str: string, options?: RangeParser.Options): RangeParser.Result | RangeParser.Ranges;
declare namespace RangeParser {
@@ -14,6 +21,10 @@ declare namespace RangeParser {
end: number;
}
interface Options {
/**
* The "combine" option can be set to `true` and overlapping & adjacent ranges
* will be combined into a single range.
*/
combine?: boolean;
}
const enum Result {