-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge package:mime into shared tool repository
- Loading branch information
Showing
24 changed files
with
3,229 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Dependabot configuration file. | ||
version: 2 | ||
|
||
updates: | ||
- package-ecosystem: github-actions | ||
directory: / | ||
schedule: | ||
interval: monthly | ||
labels: | ||
- autosubmit | ||
groups: | ||
github-actions: | ||
patterns: | ||
- "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# A workflow to close issues where the author hasn't responded to a request for | ||
# more information; see https://github.com/actions/stale. | ||
|
||
name: No Response | ||
|
||
# Run as a daily cron. | ||
on: | ||
schedule: | ||
# Every day at 8am | ||
- cron: '0 8 * * *' | ||
|
||
# All permissions not specified are set to 'none'. | ||
permissions: | ||
issues: write | ||
pull-requests: write | ||
|
||
jobs: | ||
no-response: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.repository_owner == 'dart-lang' }} | ||
steps: | ||
- uses: actions/stale@28ca1036281a5e5922ead5184a1bbf96e5fc984e | ||
with: | ||
# Don't automatically mark inactive issues+PRs as stale. | ||
days-before-stale: -1 | ||
# Close needs-info issues and PRs after 14 days of inactivity. | ||
days-before-close: 14 | ||
stale-issue-label: "needs-info" | ||
close-issue-message: > | ||
Without additional information we're not able to resolve this issue. | ||
Feel free to add more info or respond to any questions above and we | ||
can reopen the case. Thanks for your contribution! | ||
stale-pr-label: "needs-info" | ||
close-pr-message: > | ||
Without additional information we're not able to resolve this PR. | ||
Feel free to add more info or respond to any questions above. | ||
Thanks for your contribution! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# A CI configuration to auto-publish pub packages. | ||
|
||
name: Publish | ||
|
||
on: | ||
pull_request: | ||
branches: [ master ] | ||
push: | ||
tags: [ 'v[0-9]+.[0-9]+.[0-9]+' ] | ||
|
||
jobs: | ||
publish: | ||
if: ${{ github.repository_owner == 'dart-lang' }} | ||
uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main | ||
permissions: | ||
id-token: write # Required for authentication using OIDC | ||
pull-requests: write # Required for writing the pull request note |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Dart CI | ||
|
||
on: | ||
schedule: | ||
# “At 00:00 (UTC) on Sunday.” | ||
- cron: '0 0 * * 0' | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
sdk: [3.2, dev] | ||
steps: | ||
# These are the latest versions of the github actions; dependabot will | ||
# send PRs to keep these up-to-date. | ||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 | ||
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 | ||
|
||
- name: Install dependencies | ||
run: dart pub get | ||
|
||
- name: Verify formatting | ||
run: dart format --output=none --set-exit-if-changed . | ||
|
||
- name: Analyze project source | ||
run: dart analyze --fatal-infos | ||
|
||
- name: Run tests | ||
run: dart test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.packages | ||
.dart_tool/ | ||
.pub/ | ||
packages | ||
pubspec.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Below is a list of people and organizations that have contributed | ||
# to the project. Names should be added to the list like so: | ||
# | ||
# Name/Organization <email address> | ||
|
||
Google Inc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
## 1.0.6-wip | ||
|
||
* Add `topics` section to `pubspec.yaml`. | ||
|
||
## 1.0.5 | ||
|
||
* Update `video/mp4` mimeType lookup by header bytes. | ||
* Add `image/heic` mimeType lookup by header bytes. | ||
* Add `image/heif` mimeType lookup by header bytes. | ||
* Add m4b mimeType lookup by extension. | ||
* Add `text/markdown` mimeType lookup by extension. | ||
* Require Dart 3.2.0. | ||
|
||
## 1.0.4 | ||
|
||
* Changed `.js` to `text/javascript` per | ||
https://datatracker.ietf.org/doc/html/rfc9239. | ||
* Added `.mjs` as `text/javascript`. | ||
* Add `application/dicom` mimeType lookup by extension. | ||
* Require Dart 2.18. | ||
|
||
## 1.0.3 | ||
|
||
* Add application/manifest+json lookup by extension. | ||
* Add application/toml mimeType lookup by extension. | ||
* Add audio/aac mimeType lookup by header bytes. | ||
* Add audio/mpeg mimeType lookup by header bytes. | ||
* Add audio/ogg mimeType lookup by header bytes. | ||
* Add audio/weba mimeType lookup by header bytes. | ||
* Add font/woff2 lookup by extension and header bytes. | ||
* Add image/avif mimeType lookup by extension. | ||
* Add image/heic mimeType lookup by extension. | ||
* Add image/heif mimeType lookup by extension. | ||
* Change audio/x-aac to audio/aac when detected by extension. | ||
|
||
## 1.0.2 | ||
|
||
* Add audio/x-aiff mimeType lookup by header bytes. | ||
* Add audio/x-flac mimeType lookup by header bytes. | ||
* Add audio/x-wav mimeType lookup by header bytes. | ||
* Add audio/mp4 mimeType lookup by file path. | ||
|
||
## 1.0.1 | ||
|
||
* Add image/webp mimeType lookup by header bytes. | ||
|
||
## 1.0.0 | ||
|
||
* Stable null safety release. | ||
|
||
## 1.0.0-nullsafety.0 | ||
|
||
* Update to null safety. | ||
|
||
## 0.9.7 | ||
|
||
* Add `extensionFromMime` utility function. | ||
|
||
## 0.9.6+3 | ||
|
||
* Change the mime type for Dart source from `application/dart` to `text/x-dart`. | ||
* Add example. | ||
* Fix links and code in README. | ||
|
||
## 0.9.6+2 | ||
|
||
* Set max SDK version to `<3.0.0`, and adjust other dependencies. | ||
|
||
## 0.9.6+1 | ||
|
||
* Stop using deprecated constants from the SDK. | ||
|
||
## 0.9.6 | ||
|
||
* Updates to support Dart 2.0 core library changes (wave | ||
2.2). See [issue 31847][sdk#31847] for details. | ||
|
||
[sdk#31847]: https://github.com/dart-lang/sdk/issues/31847 | ||
|
||
## 0.9.5 | ||
|
||
* Add support for the WebAssembly format. | ||
|
||
## 0.9.4 | ||
|
||
* Updated Dart SDK requirement to `>= 1.8.3 <2.0.0` | ||
|
||
* Strong-mode clean. | ||
|
||
* Added support for glTF text and binary formats. | ||
|
||
## 0.9.3 | ||
|
||
* Fixed erroneous behavior for listening and when pausing/resuming | ||
stream of parts. | ||
|
||
## 0.9.2 | ||
|
||
* Fixed erroneous behavior when pausing/canceling stream of parts but already | ||
listened to one part. | ||
|
||
## 0.9.1 | ||
|
||
* Handle parsing of MIME multipart content with no parts. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Want to contribute? Great! First, read this page (including the small print at | ||
the end). | ||
|
||
### Before you contribute | ||
Before we can use your code, you must sign the | ||
[Google Individual Contributor License Agreement](https://cla.developers.google.com/about/google-individual) | ||
(CLA), which you can do online. The CLA is necessary mainly because you own the | ||
copyright to your changes, even after your contribution becomes part of our | ||
codebase, so we need your permission to use and distribute your code. We also | ||
need to be sure of various other things—for instance that you'll tell us if you | ||
know that your code infringes on other people's patents. You don't have to sign | ||
the CLA until after you've submitted your code for review and a member has | ||
approved it, but you must do it before we can put your code into our codebase. | ||
|
||
Before you start working on a larger contribution, you should get in touch with | ||
us first through the issue tracker with your idea so that we can help out and | ||
possibly guide you. Coordinating up front makes it much easier to avoid | ||
frustration later on. | ||
|
||
### Code reviews | ||
All submissions, including submissions by project members, require review. | ||
|
||
### File headers | ||
All files in the project must start with the following header. | ||
|
||
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
### The small print | ||
Contributions made by corporations are covered by a different agreement than the | ||
one above, the | ||
[Software Grant and Corporate Contributor License Agreement](https://developers.google.com/open-source/cla/corporate). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Copyright 2015, the Dart project authors. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
* Neither the name of Google LLC nor the names of its | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
[](https://github.com/dart-lang/mime/actions?query=workflow%3A"Dart+CI"+branch%3Amaster) | ||
[](https://pub.dev/packages/mime) | ||
[](https://pub.dev/packages/mime/publisher) | ||
|
||
Package for working with MIME type definitions and for processing | ||
streams of MIME multipart media types. | ||
|
||
## Determining the MIME type for a file | ||
|
||
The `MimeTypeResolver` class can be used to determine the MIME type of | ||
a file. It supports both using the extension of the file name and | ||
looking at magic bytes from the beginning of the file. | ||
|
||
There is a builtin instance of `MimeTypeResolver` accessible through | ||
the top level function `lookupMimeType`. This builtin instance has | ||
the most common file name extensions and magic bytes registered. | ||
|
||
```dart | ||
import 'package:mime/mime.dart'; | ||
void main() { | ||
print(lookupMimeType('test.html')); | ||
// text/html | ||
print(lookupMimeType('test', headerBytes: [0xFF, 0xD8])); | ||
// image/jpeg | ||
print(lookupMimeType('test.html', headerBytes: [0xFF, 0xD8])); | ||
// image/jpeg | ||
} | ||
``` | ||
|
||
You can build you own resolver by creating an instance of | ||
`MimeTypeResolver` and adding file name extensions and magic bytes | ||
using `addExtension` and `addMagicNumber`. | ||
|
||
## Processing MIME multipart media types | ||
|
||
The class `MimeMultipartTransformer` is used to process a `Stream` of | ||
bytes encoded using a MIME multipart media types encoding. The | ||
transformer provides a new `Stream` of `MimeMultipart` objects each of | ||
which have the headers and the content of each part. The content of a | ||
part is provided as a stream of bytes. | ||
|
||
Below is an example showing how to process an HTTP request and print | ||
the length of the content of each part. | ||
|
||
```dart | ||
// HTTP request with content type multipart/form-data. | ||
HttpRequest request = ...; | ||
// Determine the boundary form the content type header | ||
String boundary = request.headers.contentType.parameters['boundary']; | ||
// Process the body just calculating the length of each part. | ||
request | ||
.transform(new MimeMultipartTransformer(boundary)) | ||
.map((part) => part.fold(0, (p, d) => p + d)) | ||
.listen((length) => print('Part with length $length')); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# https://dart.dev/tools/analysis#the-analysis-options-file | ||
include: package:dart_flutter_team_lints/analysis_options.yaml | ||
|
||
analyzer: | ||
language: | ||
strict-casts: true | ||
strict-inference: true | ||
strict-raw-types: true | ||
|
||
linter: | ||
rules: | ||
- avoid_bool_literals_in_conditional_expressions | ||
- avoid_classes_with_only_static_members | ||
- avoid_private_typedef_functions | ||
- avoid_redundant_argument_values | ||
- avoid_returning_this | ||
- avoid_unused_constructor_parameters | ||
- avoid_void_async | ||
- cancel_subscriptions | ||
- join_return_with_assignment | ||
- literal_only_boolean_expressions | ||
- missing_whitespace_between_adjacent_strings | ||
- no_adjacent_strings_in_list | ||
- no_runtimeType_toString | ||
- package_api_docs | ||
- prefer_const_declarations | ||
- prefer_expression_function_bodies | ||
- prefer_final_locals | ||
- unnecessary_await_in_return | ||
- unnecessary_breaks | ||
- unnecessary_raw_strings | ||
- use_if_null_to_convert_nulls_to_bools | ||
- use_raw_strings | ||
- use_string_buffers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:mime/mime.dart'; | ||
|
||
void main() { | ||
print(lookupMimeType('test.html')); | ||
// text/html | ||
|
||
print(lookupMimeType('test', headerBytes: [0xFF, 0xD8])); | ||
// image/jpeg | ||
|
||
print(lookupMimeType('test.html', headerBytes: [0xFF, 0xD8])); | ||
// image/jpeg | ||
} |
Oops, something went wrong.