Skip to content

Commit b98c535

Browse files
authored
Merge pull request #388 from dart-lang/merge-mime-package
Merge mime package
2 parents bc35f17 + 49acd78 commit b98c535

22 files changed

+3176
-0
lines changed

.github/workflows/mime.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Dart CI
2+
3+
on:
4+
schedule:
5+
# “At 00:00 (UTC) on Sunday.”
6+
- cron: '0 0 * * 0'
7+
push:
8+
branches: [ main ]
9+
paths:
10+
- '.github/workflows/mime.yml'
11+
- 'pkgs/mime/**'
12+
pull_request:
13+
branches: [ main ]
14+
paths:
15+
- '.github/workflows/mime.yml'
16+
- 'pkgs/mime/**'
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
defaults:
22+
run:
23+
working-directory: pkgs/mime/
24+
25+
strategy:
26+
matrix:
27+
os: [ubuntu-latest]
28+
sdk: [3.2, dev]
29+
steps:
30+
# These are the latest versions of the github actions; dependabot will
31+
# send PRs to keep these up-to-date.
32+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
33+
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
34+
35+
- name: Install dependencies
36+
run: dart pub get
37+
38+
- name: Verify formatting
39+
run: dart format --output=none --set-exit-if-changed .
40+
41+
- name: Analyze project source
42+
run: dart analyze --fatal-infos
43+
44+
- name: Run tests
45+
run: dart test

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ don't naturally belong to other topic monorepos (like
2020
| [unified_analytics](pkgs/unified_analytics/) | A package for logging analytics for all Dart and Flutter related tooling to Google Analytics. | [![pub package](https://img.shields.io/pub/v/unified_analytics.svg)](https://pub.dev/packages/unified_analytics) |
2121
| [source_map_stack_trace](pkgs/source_map_stack_trace/) | A package for applying source maps to stack traces. | [![pub package](https://img.shields.io/pub/v/source_map_stack_trace.svg)](https://pub.dev/packages/source_map_stack_trace) |
2222
| [oauth2](pkgs/oauth2/) | A client library for authenticatingand making requests via OAuth2. | [![pub package](https://img.shields.io/pub/v/oauth2.svg)](https://pub.dev/packages/oauth2) |
23+
| [mime](pkgs/mime/) | Utilities for handling media (MIME) types. | [![pub package](https://img.shields.io/pub/v/mime.svg)](https://pub.dev/packages/mime) |
2324

2425
## Publishing automation
2526

pkgs/mime/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.packages
2+
.dart_tool/
3+
.pub/
4+
packages
5+
pubspec.lock

pkgs/mime/AUTHORS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Below is a list of people and organizations that have contributed
2+
# to the project. Names should be added to the list like so:
3+
#
4+
# Name/Organization <email address>
5+
6+
Google Inc.

pkgs/mime/CHANGELOG.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
## 1.0.6
2+
3+
* Add `topics` section to `pubspec.yaml`.
4+
* Move to `dart-lang/tools` monorepo.
5+
6+
## 1.0.5
7+
8+
* Update `video/mp4` mimeType lookup by header bytes.
9+
* Add `image/heic` mimeType lookup by header bytes.
10+
* Add `image/heif` mimeType lookup by header bytes.
11+
* Add m4b mimeType lookup by extension.
12+
* Add `text/markdown` mimeType lookup by extension.
13+
* Require Dart 3.2.0.
14+
15+
## 1.0.4
16+
17+
* Changed `.js` to `text/javascript` per
18+
https://datatracker.ietf.org/doc/html/rfc9239.
19+
* Added `.mjs` as `text/javascript`.
20+
* Add `application/dicom` mimeType lookup by extension.
21+
* Require Dart 2.18.
22+
23+
## 1.0.3
24+
25+
* Add application/manifest+json lookup by extension.
26+
* Add application/toml mimeType lookup by extension.
27+
* Add audio/aac mimeType lookup by header bytes.
28+
* Add audio/mpeg mimeType lookup by header bytes.
29+
* Add audio/ogg mimeType lookup by header bytes.
30+
* Add audio/weba mimeType lookup by header bytes.
31+
* Add font/woff2 lookup by extension and header bytes.
32+
* Add image/avif mimeType lookup by extension.
33+
* Add image/heic mimeType lookup by extension.
34+
* Add image/heif mimeType lookup by extension.
35+
* Change audio/x-aac to audio/aac when detected by extension.
36+
37+
## 1.0.2
38+
39+
* Add audio/x-aiff mimeType lookup by header bytes.
40+
* Add audio/x-flac mimeType lookup by header bytes.
41+
* Add audio/x-wav mimeType lookup by header bytes.
42+
* Add audio/mp4 mimeType lookup by file path.
43+
44+
## 1.0.1
45+
46+
* Add image/webp mimeType lookup by header bytes.
47+
48+
## 1.0.0
49+
50+
* Stable null safety release.
51+
52+
## 1.0.0-nullsafety.0
53+
54+
* Update to null safety.
55+
56+
## 0.9.7
57+
58+
* Add `extensionFromMime` utility function.
59+
60+
## 0.9.6+3
61+
62+
* Change the mime type for Dart source from `application/dart` to `text/x-dart`.
63+
* Add example.
64+
* Fix links and code in README.
65+
66+
## 0.9.6+2
67+
68+
* Set max SDK version to `<3.0.0`, and adjust other dependencies.
69+
70+
## 0.9.6+1
71+
72+
* Stop using deprecated constants from the SDK.
73+
74+
## 0.9.6
75+
76+
* Updates to support Dart 2.0 core library changes (wave
77+
2.2). See [issue 31847][sdk#31847] for details.
78+
79+
[sdk#31847]: https://github.com/dart-lang/sdk/issues/31847
80+
81+
## 0.9.5
82+
83+
* Add support for the WebAssembly format.
84+
85+
## 0.9.4
86+
87+
* Updated Dart SDK requirement to `>= 1.8.3 <2.0.0`
88+
89+
* Strong-mode clean.
90+
91+
* Added support for glTF text and binary formats.
92+
93+
## 0.9.3
94+
95+
* Fixed erroneous behavior for listening and when pausing/resuming
96+
stream of parts.
97+
98+
## 0.9.2
99+
100+
* Fixed erroneous behavior when pausing/canceling stream of parts but already
101+
listened to one part.
102+
103+
## 0.9.1
104+
105+
* Handle parsing of MIME multipart content with no parts.

pkgs/mime/CONTRIBUTING.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Want to contribute? Great! First, read this page (including the small print at
2+
the end).
3+
4+
### Before you contribute
5+
Before we can use your code, you must sign the
6+
[Google Individual Contributor License Agreement](https://cla.developers.google.com/about/google-individual)
7+
(CLA), which you can do online. The CLA is necessary mainly because you own the
8+
copyright to your changes, even after your contribution becomes part of our
9+
codebase, so we need your permission to use and distribute your code. We also
10+
need to be sure of various other things—for instance that you'll tell us if you
11+
know that your code infringes on other people's patents. You don't have to sign
12+
the CLA until after you've submitted your code for review and a member has
13+
approved it, but you must do it before we can put your code into our codebase.
14+
15+
Before you start working on a larger contribution, you should get in touch with
16+
us first through the issue tracker with your idea so that we can help out and
17+
possibly guide you. Coordinating up front makes it much easier to avoid
18+
frustration later on.
19+
20+
### Code reviews
21+
All submissions, including submissions by project members, require review.
22+
23+
### File headers
24+
All files in the project must start with the following header.
25+
26+
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
27+
// for details. All rights reserved. Use of this source code is governed by a
28+
// BSD-style license that can be found in the LICENSE file.
29+
30+
### The small print
31+
Contributions made by corporations are covered by a different agreement than the
32+
one above, the
33+
[Software Grant and Corporate Contributor License Agreement](https://developers.google.com/open-source/cla/corporate).

pkgs/mime/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2015, the Dart project authors.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the name of Google LLC nor the names of its
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

pkgs/mime/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[![Build Status](https://github.com/dart-lang/tools/actions/workflows/mime.yml/badge.svg)](https://github.com/dart-lang/tools/actions/workflows/mime.yml)
2+
[![Pub Package](https://img.shields.io/pub/v/mime.svg)](https://pub.dev/packages/mime)
3+
[![package publisher](https://img.shields.io/pub/publisher/mime.svg)](https://pub.dev/packages/mime/publisher)
4+
5+
Package for working with MIME type definitions and for processing
6+
streams of MIME multipart media types.
7+
8+
## Determining the MIME type for a file
9+
10+
The `MimeTypeResolver` class can be used to determine the MIME type of
11+
a file. It supports both using the extension of the file name and
12+
looking at magic bytes from the beginning of the file.
13+
14+
There is a builtin instance of `MimeTypeResolver` accessible through
15+
the top level function `lookupMimeType`. This builtin instance has
16+
the most common file name extensions and magic bytes registered.
17+
18+
```dart
19+
import 'package:mime/mime.dart';
20+
21+
void main() {
22+
print(lookupMimeType('test.html'));
23+
// text/html
24+
25+
print(lookupMimeType('test', headerBytes: [0xFF, 0xD8]));
26+
// image/jpeg
27+
28+
print(lookupMimeType('test.html', headerBytes: [0xFF, 0xD8]));
29+
// image/jpeg
30+
}
31+
```
32+
33+
You can build you own resolver by creating an instance of
34+
`MimeTypeResolver` and adding file name extensions and magic bytes
35+
using `addExtension` and `addMagicNumber`.
36+
37+
## Processing MIME multipart media types
38+
39+
The class `MimeMultipartTransformer` is used to process a `Stream` of
40+
bytes encoded using a MIME multipart media types encoding. The
41+
transformer provides a new `Stream` of `MimeMultipart` objects each of
42+
which have the headers and the content of each part. The content of a
43+
part is provided as a stream of bytes.
44+
45+
Below is an example showing how to process an HTTP request and print
46+
the length of the content of each part.
47+
48+
```dart
49+
// HTTP request with content type multipart/form-data.
50+
HttpRequest request = ...;
51+
// Determine the boundary form the content type header
52+
String boundary = request.headers.contentType.parameters['boundary'];
53+
54+
// Process the body just calculating the length of each part.
55+
request
56+
.transform(new MimeMultipartTransformer(boundary))
57+
.map((part) => part.fold(0, (p, d) => p + d))
58+
.listen((length) => print('Part with length $length'));
59+
```

pkgs/mime/analysis_options.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# https://dart.dev/tools/analysis#the-analysis-options-file
2+
include: package:dart_flutter_team_lints/analysis_options.yaml
3+
4+
analyzer:
5+
language:
6+
strict-casts: true
7+
strict-inference: true
8+
strict-raw-types: true
9+
10+
linter:
11+
rules:
12+
- avoid_bool_literals_in_conditional_expressions
13+
- avoid_classes_with_only_static_members
14+
- avoid_private_typedef_functions
15+
- avoid_redundant_argument_values
16+
- avoid_returning_this
17+
- avoid_unused_constructor_parameters
18+
- avoid_void_async
19+
- cancel_subscriptions
20+
- join_return_with_assignment
21+
- literal_only_boolean_expressions
22+
- missing_whitespace_between_adjacent_strings
23+
- no_adjacent_strings_in_list
24+
- no_runtimeType_toString
25+
- package_api_docs
26+
- prefer_const_declarations
27+
- prefer_expression_function_bodies
28+
- prefer_final_locals
29+
- unnecessary_await_in_return
30+
- unnecessary_breaks
31+
- unnecessary_raw_strings
32+
- use_if_null_to_convert_nulls_to_bools
33+
- use_raw_strings
34+
- use_string_buffers

pkgs/mime/example/example.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:mime/mime.dart';
6+
7+
void main() {
8+
print(lookupMimeType('test.html'));
9+
// text/html
10+
11+
print(lookupMimeType('test', headerBytes: [0xFF, 0xD8]));
12+
// image/jpeg
13+
14+
print(lookupMimeType('test.html', headerBytes: [0xFF, 0xD8]));
15+
// image/jpeg
16+
}

0 commit comments

Comments
 (0)