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

Side by Side Diff: pkg/mime/lib/src/magic_number.dart

Issue 272353002: pkg/mime: layout as mini-libraries (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: cl nits, other fixes Created 6 years, 7 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 | Annotate | Revision Log
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 part of mime; 5 library mime.magic_number;
6 6
7 7 class MagicNumber {
8 class _MagicNumber {
9 final String mimeType; 8 final String mimeType;
10 final List<int> numbers; 9 final List<int> numbers;
11 final List<int> mask; 10 final List<int> mask;
12 11
13 const _MagicNumber(this.mimeType, this.numbers, {this.mask}); 12 const MagicNumber(this.mimeType, this.numbers, {this.mask});
14 13
15 bool matches(List<int> header) { 14 bool matches(List<int> header) {
16 if (header.length < numbers.length) return false; 15 if (header.length < numbers.length) return false;
17 16
18 for (int i = 0; i < numbers.length; i++) { 17 for (int i = 0; i < numbers.length; i++) {
19 if (mask != null) { 18 if (mask != null) {
20 if ((mask[i] & numbers[i]) != (mask[i] & header[i])) return false; 19 if ((mask[i] & numbers[i]) != (mask[i] & header[i])) return false;
21 } else { 20 } else {
22 if (numbers[i] != header[i]) return false; 21 if (numbers[i] != header[i]) return false;
23 } 22 }
24 } 23 }
25 24
26 return true; 25 return true;
27 } 26 }
28 27
29 } 28 }
30 29
31 const int _DEFAULT_MAGIC_NUMBERS_MAX_LENGTH = 16; 30 const List<MagicNumber> DEFAULT_MAGIC_NUMBERS = const [
32 31 const MagicNumber('application/pdf', const [0x25, 0x50, 0x44, 0x46]),
33 const List<_MagicNumber> _DEFAULT_MAGIC_NUMBERS = const [ 32 const MagicNumber('application/postscript', const [0x25, 0x51]),
34 const _MagicNumber('application/pdf', const [0x25, 0x50, 0x44, 0x46]), 33 const MagicNumber('image/gif', const [0x47, 0x49, 0x46, 0x38, 0x37, 0x61]),
35 const _MagicNumber('application/postscript', const [0x25, 0x51]), 34 const MagicNumber('image/gif', const [0x47, 0x49, 0x46, 0x38, 0x39, 0x61]),
36 const _MagicNumber('image/gif', const [0x47, 0x49, 0x46, 0x38, 0x37, 0x61]), 35 const MagicNumber('image/jpeg', const [0xFF, 0xD8]),
37 const _MagicNumber('image/gif', const [0x47, 0x49, 0x46, 0x38, 0x39, 0x61]), 36 const MagicNumber('image/png',
38 const _MagicNumber('image/jpeg', const [0xFF, 0xD8]),
39 const _MagicNumber('image/png',
40 const [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]), 37 const [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]),
41 const _MagicNumber('image/tiff', const [0x49, 0x49, 0x2A, 0x00]), 38 const MagicNumber('image/tiff', const [0x49, 0x49, 0x2A, 0x00]),
42 const _MagicNumber('image/tiff', const [0x4D, 0x4D, 0x00, 0x2A]), 39 const MagicNumber('image/tiff', const [0x4D, 0x4D, 0x00, 0x2A]),
43 const _MagicNumber( 40 const MagicNumber(
44 'video/mp4', 41 'video/mp4',
45 const [0x00, 0x00, 0x00, 0x00, 0x66, 0x74, 42 const [0x00, 0x00, 0x00, 0x00, 0x66, 0x74,
46 0x79, 0x70, 0x33, 0x67, 0x70, 0x35], 43 0x79, 0x70, 0x33, 0x67, 0x70, 0x35],
47 mask: const [0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 44 mask: const [0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF,
48 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]) 45 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF])
49 ]; 46 ];
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698