Skip to content
Snippets Groups Projects
Commit 76333411 authored by ajohnsen@google.com's avatar ajohnsen@google.com
Browse files

Clean up mime package.

Also speed up default mime-type map, by not using a const map.

BUG=
R=kevmoo@google.com

Review URL: https://codereview.chromium.org//292983002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/mime@36543 260f80e4-7a28-3924-810f-c04153c831b5
parent 04b097cc
No related branches found
No related tags found
No related merge requests found
......@@ -4,8 +4,8 @@
library mime.extension_map;
// TODO(ajohnsen): Use sorted list and binary search?
const Map<String, String> DEFAULT_EXTENSION_MAP = const <String, String>{
// TODO(ajohnsen): Use const map once Issue 7559 is fixed.
final Map<String, String> defaultExtensionMap = <String, String>{
'123':'application/vnd.lotus-1-2-3',
'3dml':'text/vnd.in3d.3dml',
'3ds':'image/x-3ds',
......
......@@ -27,6 +27,8 @@ class MagicNumber {
}
const int DEFAULT_MAGIC_NUMBERS_MAX_LENGTH = 12;
const List<MagicNumber> DEFAULT_MAGIC_NUMBERS = const [
const MagicNumber('application/pdf', const [0x25, 0x50, 0x44, 0x46]),
const MagicNumber('application/postscript', const [0x25, 0x51]),
......
......@@ -12,8 +12,7 @@ final MimeTypeResolver _globalResolver = new MimeTypeResolver();
/**
* The maximum number of bytes needed, to match all default magic-numbers.
*/
// NOTE: this is not formatted AS_A_CONST to avoid a breaking change
const int defaultMagicNumbersMaxLength = 12;
int get defaultMagicNumbersMaxLength => _globalResolver.magicNumbersMaxLength;
/**
* Extract the extension from [path] and use that for MIME-type lookup, using
......@@ -49,7 +48,7 @@ class MimeTypeResolver {
*/
MimeTypeResolver() :
_useDefault = true,
_magicNumbersMaxLength = defaultMagicNumbersMaxLength;
_magicNumbersMaxLength = DEFAULT_MAGIC_NUMBERS_MAX_LENGTH;
/**
* Get the maximum number of bytes required to match all magic numbers, when
......@@ -82,7 +81,7 @@ class MimeTypeResolver {
result = _extensionMap[ext];
if (result != null) return result;
if (_useDefault) {
result = DEFAULT_EXTENSION_MAP[ext];
result = defaultExtensionMap[ext];
if (result != null) return result;
}
return null;
......
name: mime
version: 0.9.0+1
version: 0.9.0+2
author: Dart Team <misc@dartlang.org>
description: Helper-package for working with MIME.
homepage: http://www.dartlang.org
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment