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

Side by Side Diff: lib/src/magic_number.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/bound_multipart_stream.dart ('k') | lib/src/mime_multipart_transformer.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.magic_number; 5 library mime.magic_number;
6 6
7 class MagicNumber { 7 class MagicNumber {
8 final String mimeType; 8 final String mimeType;
9 final List<int> numbers; 9 final List<int> numbers;
10 final List<int> mask; 10 final List<int> mask;
11 11
12 const MagicNumber(this.mimeType, this.numbers, {this.mask}); 12 const MagicNumber(this.mimeType, this.numbers, {this.mask});
13 13
14 bool matches(List<int> header) { 14 bool matches(List<int> header) {
15 if (header.length < numbers.length) return false; 15 if (header.length < numbers.length) return false;
16 16
17 for (int i = 0; i < numbers.length; i++) { 17 for (int i = 0; i < numbers.length; i++) {
18 if (mask != null) { 18 if (mask != null) {
19 if ((mask[i] & numbers[i]) != (mask[i] & header[i])) return false; 19 if ((mask[i] & numbers[i]) != (mask[i] & header[i])) return false;
20 } else { 20 } else {
21 if (numbers[i] != header[i]) return false; 21 if (numbers[i] != header[i]) return false;
22 } 22 }
23 } 23 }
24 24
25 return true; 25 return true;
26 } 26 }
27
28 } 27 }
29 28
30 const int DEFAULT_MAGIC_NUMBERS_MAX_LENGTH = 12; 29 const int DEFAULT_MAGIC_NUMBERS_MAX_LENGTH = 12;
31 30
32 const List<MagicNumber> DEFAULT_MAGIC_NUMBERS = const [ 31 const List<MagicNumber> DEFAULT_MAGIC_NUMBERS = const [
33 const MagicNumber('application/pdf', const [0x25, 0x50, 0x44, 0x46]), 32 const MagicNumber('application/pdf', const [0x25, 0x50, 0x44, 0x46]),
34 const MagicNumber('application/postscript', const [0x25, 0x51]), 33 const MagicNumber('application/postscript', const [0x25, 0x51]),
35 const MagicNumber('image/gif', const [0x47, 0x49, 0x46, 0x38, 0x37, 0x61]), 34 const MagicNumber('image/gif', const [0x47, 0x49, 0x46, 0x38, 0x37, 0x61]),
36 const MagicNumber('image/gif', const [0x47, 0x49, 0x46, 0x38, 0x39, 0x61]), 35 const MagicNumber('image/gif', const [0x47, 0x49, 0x46, 0x38, 0x39, 0x61]),
37 const MagicNumber('image/jpeg', const [0xFF, 0xD8]), 36 const MagicNumber('image/jpeg', const [0xFF, 0xD8]),
38 const MagicNumber('image/png', 37 const MagicNumber(
39 const [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]), 38 'image/png', const [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]),
40 const MagicNumber('image/tiff', const [0x49, 0x49, 0x2A, 0x00]), 39 const MagicNumber('image/tiff', const [0x49, 0x49, 0x2A, 0x00]),
41 const MagicNumber('image/tiff', const [0x4D, 0x4D, 0x00, 0x2A]), 40 const MagicNumber('image/tiff', const [0x4D, 0x4D, 0x00, 0x2A]),
42 const MagicNumber( 41 const MagicNumber(
43 'video/mp4', 42 'video/mp4',
44 const [0x00, 0x00, 0x00, 0x00, 0x66, 0x74, 43 const [0x00, 0x00, 0x00, 0x00, 0x66, 0x74,
45 0x79, 0x70, 0x33, 0x67, 0x70, 0x35], 44 0x79, 0x70, 0x33, 0x67, 0x70, 0x35],
46 mask: const [0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 45 mask: const [0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF,
47 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]) 46 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF])
48 ]; 47 ];
OLDNEW
« no previous file with comments | « lib/src/bound_multipart_stream.dart ('k') | lib/src/mime_multipart_transformer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698