range_header 2.0.2+2

  • Readme
  • Changelog
  • Example
  • Installing
  • 54

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]
24
Health:
Code health derived from static analysis. [more]
74
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
54
Learn more about scoring.

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

  • Dart: 2.6.1
  • pana: 0.13.1+4

Health suggestions

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

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

line 9 col 24: Unnecessary new keyword.

line 10 col 23: Unnecessary new keyword.

line 23 col 17: Unnecessary new keyword.

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

line 30 col 18: Unnecessary new keyword.

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

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

line 22 col 13: Unnecessary new keyword.

line 62 col 16: Unnecessary new keyword.

line 64 col 5: Unnecessary new keyword.

line 66 col 22: Unnecessary new keyword.

line 67 col 15: Unnecessary new keyword.

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

Analysis of lib/src/range_header_item.dart reported 7 hints, including:

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

line 17 col 13: Unnecessary new keyword.

line 18 col 12: Unnecessary new keyword.

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.

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

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

line 17 col 15: Unnecessary new keyword.

line 30 col 12: Unnecessary new keyword.

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

line 43 col 18: Unnecessary new keyword.

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

Fix lib/src/range_header_impl.dart. (-0.50 points)

Analysis of lib/src/range_header_impl.dart reported 1 hint:

line 16 col 19: Unnecessary new keyword.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
async ^2.0.0 2.4.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.8
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