2021-09-12 01:23:12 +00:00
|
|
|
# Belatuk Range Header
|
|
|
|
|
2021-09-16 03:23:05 +00:00
|
|
|
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/belatuk_range_header?include_prereleases)
|
2021-09-12 01:23:12 +00:00
|
|
|
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
2021-09-12 03:21:17 +00:00
|
|
|
[![License](https://img.shields.io/github/license/dart-backend/belatuk-common-utilities)](https://github.com/dart-backend/belatuk-common-utilities/blob/main/packages/range_header/LICENSE)
|
2021-09-12 01:23:12 +00:00
|
|
|
|
|
|
|
**Replacement of `package:range_header` with breaking changes to support NNBD.**
|
|
|
|
|
|
|
|
Range header parser for belatuk. Can be used by any dart backend.
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
In your `pubspec.yaml`:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
dependencies:
|
2023-12-12 02:10:10 +00:00
|
|
|
belatuk_range_header: ^6.2.0
|
2021-09-12 01:23:12 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
```dart
|
|
|
|
handleRequest(HttpRequest request) async {
|
|
|
|
// Parse the header
|
|
|
|
var header = RangeHeader.parse(request.headers.value(HttpHeaders.rangeHeader));
|
|
|
|
|
|
|
|
// Optimize/canonicalize it
|
|
|
|
var items = RangeHeader.foldItems(header.items);
|
|
|
|
header = RangeHeader(items);
|
|
|
|
|
|
|
|
// Get info
|
|
|
|
header.items;
|
|
|
|
header.rangeUnit;
|
|
|
|
print(header.items[0].toContentRange(fileSize));
|
|
|
|
|
|
|
|
// Serve the file
|
|
|
|
var transformer = RangeHeaderTransformer(header);
|
|
|
|
await file.openRead().transform(transformer).pipe(request.response);
|
|
|
|
}
|
|
|
|
```
|