Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(442)

Side by Side Diff: lib/src/mime_type.dart

Issue 1315033002: pkg/mime: dartfmt most of the code (Closed) Base URL: https://github.com/dart-lang/mime.git@master
Patch Set: rebase Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/mime_multipart_transformer.dart ('k') | test/mime_multipart_transformer_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library mime.mime_type; 5 library mime.mime_type;
6 6
7 import 'default_extension_map.dart'; 7 import 'default_extension_map.dart';
8 import 'magic_number.dart'; 8 import 'magic_number.dart';
9 9
10 final MimeTypeResolver _globalResolver = new MimeTypeResolver(); 10 final MimeTypeResolver _globalResolver = new MimeTypeResolver();
(...skipping 23 matching lines...) Expand all
34 */ 34 */
35 class MimeTypeResolver { 35 class MimeTypeResolver {
36 final Map<String, String> _extensionMap = {}; 36 final Map<String, String> _extensionMap = {};
37 final List<MagicNumber> _magicNumbers = []; 37 final List<MagicNumber> _magicNumbers = [];
38 final bool _useDefault; 38 final bool _useDefault;
39 int _magicNumbersMaxLength; 39 int _magicNumbersMaxLength;
40 40
41 /** 41 /**
42 * Create a new empty [MimeTypeResolver]. 42 * Create a new empty [MimeTypeResolver].
43 */ 43 */
44 MimeTypeResolver.empty() : _useDefault = false, _magicNumbersMaxLength = 0; 44 MimeTypeResolver.empty()
45 : _useDefault = false,
46 _magicNumbersMaxLength = 0;
45 47
46 /** 48 /**
47 * Create a new [MimeTypeResolver] containing the default scope. 49 * Create a new [MimeTypeResolver] containing the default scope.
48 */ 50 */
49 MimeTypeResolver() : 51 MimeTypeResolver()
50 _useDefault = true, 52 : _useDefault = true,
51 _magicNumbersMaxLength = DEFAULT_MAGIC_NUMBERS_MAX_LENGTH; 53 _magicNumbersMaxLength = DEFAULT_MAGIC_NUMBERS_MAX_LENGTH;
52 54
53 /** 55 /**
54 * Get the maximum number of bytes required to match all magic numbers, when 56 * Get the maximum number of bytes required to match all magic numbers, when
55 * performing [lookup] with headerBytes present. 57 * performing [lookup] with headerBytes present.
56 */ 58 */
57 int get magicNumbersMaxLength => _magicNumbersMaxLength; 59 int get magicNumbersMaxLength => _magicNumbersMaxLength;
58 60
59 /** 61 /**
60 * Extract the extension from [path] and use that for MIME-type lookup. 62 * Extract the extension from [path] and use that for MIME-type lookup.
61 * 63 *
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 void addMagicNumber(List<int> bytes, String mimeType, {List<int> mask}) { 106 void addMagicNumber(List<int> bytes, String mimeType, {List<int> mask}) {
105 if (mask != null && bytes.length != mask.length) { 107 if (mask != null && bytes.length != mask.length) {
106 throw new ArgumentError('Bytes and mask are of different lengths'); 108 throw new ArgumentError('Bytes and mask are of different lengths');
107 } 109 }
108 if (bytes.length > _magicNumbersMaxLength) { 110 if (bytes.length > _magicNumbersMaxLength) {
109 _magicNumbersMaxLength = bytes.length; 111 _magicNumbersMaxLength = bytes.length;
110 } 112 }
111 _magicNumbers.add(new MagicNumber(mimeType, bytes, mask: mask)); 113 _magicNumbers.add(new MagicNumber(mimeType, bytes, mask: mask));
112 } 114 }
113 115
114 static String _matchMagic(List<int> headerBytes, 116 static String _matchMagic(
115 List<MagicNumber> magicNumbers) { 117 List<int> headerBytes, List<MagicNumber> magicNumbers) {
116 for (var mn in magicNumbers) { 118 for (var mn in magicNumbers) {
117 if (mn.matches(headerBytes)) return mn.mimeType; 119 if (mn.matches(headerBytes)) return mn.mimeType;
118 } 120 }
119 return null; 121 return null;
120 } 122 }
121 123
122 static String _ext(String path) { 124 static String _ext(String path) {
123 int index = path.lastIndexOf('.'); 125 int index = path.lastIndexOf('.');
124 if (index < 0 || index + 1 >= path.length) return path; 126 if (index < 0 || index + 1 >= path.length) return path;
125 return path.substring(index + 1).toLowerCase(); 127 return path.substring(index + 1).toLowerCase();
126 } 128 }
127 } 129 }
128
OLDNEW
« no previous file with comments | « lib/src/mime_multipart_transformer.dart ('k') | test/mime_multipart_transformer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698