range_header 2.0.2+2

range_header #

Pub build status

Range header parser for Dart.

Installation #

In your pubspec.yaml:

dependencies:
  range_header: ^2.0.0

Usage #

handleRequest(HttpRequest request) async {
  // Parse the header
  var header = new RangeHeader.parse(request.headers.value(HttpHeaders.rangeHeader));

  // Optimize/canonicalize it
  var items = RangeHeader.foldItems(header.items);
  header = new RangeHeader(items);

  // Get info
  header.items;
  header.rangeUnit;
  print(header.items[0].toContentRange(fileSize));

  // Serve the file
  var transformer = new RangeHeaderTransformer(header);
  await file.openRead().transform(transformer).pipe(request.response);
}

2.0.2 #

  • Fix bug in toContentRange that printed invalid indices.
  • Fold header items by default.

2.0.1 #

  • Adjust RangeHeaderTransformer to properly print the content range of each item, when multiple are present.

2.0.0 #

  • Dart 2 update.
  • Add RangeHeaderTransformer.
  • Overall restructuring/refactoring.

example/main.dart

import 'dart:io';
import 'package:range_header/range_header.dart';

var file = new File('some_video.mp4');

handleRequest(HttpRequest request) async {
  // Parse the header
  var header =
      new RangeHeader.parse(request.headers.value(HttpHeaders.rangeHeader));

  // Optimize/canonicalize it
  var items = RangeHeader.foldItems(header.items);
  header = new RangeHeader(items);

  // Get info
  header.items;
  header.rangeUnit;
  header.items.forEach((item) => item.toContentRange(400));

  // Serve the file
  var transformer =
      new RangeHeaderTransformer(header, 'video/mp4', await file.length());
  await file.openRead().transform(transformer).pipe(request.response);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  range_header: ^2.0.2+2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:range_header/range_header.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
13
Health:
Code health derived from static analysis. [more]
88
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
53
Learn more about scoring.

We analyzed this package on Aug 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, other

Primary library: package:range_header/range_header.dart with components: io.

Health suggestions

Fix lib/src/parser.dart. (-6.78 points)

Analysis of lib/src/parser.dart reported 14 hints, including:

line 30 col 7: DO use curly braces for all flow control structures.

line 32 col 7: DO use curly braces for all flow control structures.

line 34 col 7: DO use curly braces for all flow control structures.

line 36 col 7: DO use curly braces for all flow control structures.

line 83 col 7: DO use curly braces for all flow control structures.

Fix lib/src/converter.dart. (-2.96 points)

Analysis of lib/src/converter.dart reported 6 hints, including:

line 123 col 39: DO use curly braces for all flow control structures.

line 124 col 35: DO use curly braces for all flow control structures.

line 144 col 7: Future results in async function bodies must be awaited or marked unawaited using package:pedantic.

line 153 col 16: Use = to separate a named parameter from its default value.

line 154 col 22: Use = to separate a named parameter from its default value.

Fix lib/src/range_header_item.dart. (-1.99 points)

Analysis of lib/src/range_header_item.dart reported 4 hints:

line 17 col 7: DO use curly braces for all flow control structures.

line 59 col 7: DO use curly braces for all flow control structures.

line 61 col 7: DO use curly braces for all flow control structures.

line 63 col 7: DO use curly braces for all flow control structures.

Fix lib/src/range_header.dart. (-1 points)

Analysis of lib/src/range_header.dart reported 2 hints:

line 41 col 53: Use = to separate a named parameter from its default value.

line 58 col 58: Use = to separate a named parameter from its default value.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
async ^2.0.0 2.3.0
charcode ^1.0.0 1.1.2
quiver_hashcode ^2.0.0 2.0.0
source_span ^1.0.0 1.5.5
string_scanner ^1.0.0 1.0.5
Transitive dependencies
collection 1.14.12
meta 1.1.7
path 1.6.4
term_glyph 1.1.0
Dev dependencies
angel_framework any
angel_static ^2.0.0
file any
http_parser ^3.0.0
logging ^0.11.0
test ^1.0.0