platform/packages/range_header/README.md

39 lines
1.1 KiB
Markdown
Raw Normal View History

2021-05-15 11:58:09 +00:00
# angel3_range_header
2021-05-18 11:58:51 +00:00
[![version](https://img.shields.io/badge/pub-v3.0.1-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
Range header parser for Dart.
# Installation
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
```
# Usage
```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);
}
```