platform/packages/range_header/README.md

43 lines
1.3 KiB
Markdown
Raw Normal View History

2021-07-15 08:41:30 +00:00
# Angel3 Range Header
2021-09-12 12:17:05 +00:00
[![version](https://img.shields.io/badge/pub-v3.0.3-brightgreen)](https://pub.dartlang.org/packages/angel3_range_header)
2021-05-15 11:58:09 +00:00
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
2021-05-01 02:48:36 +00:00
2021-05-15 11:58:09 +00:00
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/range_header/LICENSE)
2021-05-01 02:48:36 +00:00
2021-09-12 12:17:05 +00:00
**DEPRECATED: Replaced by [`belatuk_range_header`](https://pub.dartlang.org/packages/belatuk_range_header) package**
2021-07-15 08:41:30 +00:00
Range header parser for Angel3. Can be used by any dart backend.
## Installation
2021-05-01 02:48:36 +00:00
In your `pubspec.yaml`:
```yaml
dependencies:
2021-05-15 11:58:09 +00:00
angel3_range_header: ^3.0.0
2021-05-01 02:48:36 +00:00
```
2021-07-15 08:41:30 +00:00
## Usage
2021-05-01 02:48:36 +00:00
```dart
handleRequest(HttpRequest request) async {
// Parse the header
2021-05-15 11:58:09 +00:00
var header = RangeHeader.parse(request.headers.value(HttpHeaders.rangeHeader));
2021-05-01 02:48:36 +00:00
// Optimize/canonicalize it
var items = RangeHeader.foldItems(header.items);
2021-05-15 11:58:09 +00:00
header = RangeHeader(items);
2021-05-01 02:48:36 +00:00
// Get info
header.items;
header.rangeUnit;
print(header.items[0].toContentRange(fileSize));
// Serve the file
2021-05-15 11:58:09 +00:00
var transformer = RangeHeaderTransformer(header);
2021-05-01 02:48:36 +00:00
await file.openRead().transform(transformer).pipe(request.response);
}
```