OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 part of mime; | |
6 | |
7 | |
8 class _MagicNumber { | |
9 final String mimeType; | |
10 final List<int> numbers; | |
11 final List<int> mask; | |
12 | |
13 const _MagicNumber(this.mimeType, this.numbers, {this.mask}); | |
14 | |
15 bool matches(List<int> header) { | |
16 if (header.length < numbers.length) return false; | |
17 | |
18 for (int i = 0; i < numbers.length; i++) { | |
19 if (mask != null && mask[i] == 0) continue; | |
20 if (numbers[i] != header[i]) return false; | |
21 } | |
22 | |
23 return true; | |
24 } | |
25 | |
26 } | |
27 | |
28 int _defaultMagicNumbersMaxLength = 16; | |
29 | |
30 List<_MagicNumber> _defaultMagicNumbers = const [ | |
31 const _MagicNumber('application/pdf', const [0x25, 0x50, 0x44, 0x46]), | |
32 const _MagicNumber('application/postscript', const [0x25, 0x51]), | |
33 const _MagicNumber('image/gif', const [0x47, 0x49, 0x46, 0x38, 0x37, 0x61]), | |
34 const _MagicNumber('image/gif', const [0x47, 0x49, 0x46, 0x38, 0x39, 0x61]), | |
35 const _MagicNumber('image/jpeg', const [0xFF, 0xD8]), | |
36 const _MagicNumber('image/png', | |
37 const [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]), | |
38 const _MagicNumber('image/tiff', const [0x49, 0x49, 0x2A, 0x00]), | |
39 const _MagicNumber('image/tiff', const [0x4D, 0x4D, 0x00, 0x2A]), | |
40 const _MagicNumber('video/mp4', | |
41 const [0x00, 0x00, 0x00, 0x00, 0x66, 0x74, | |
42 0x79, 0x70, 0x33, 0x67, 0x70, 0x35], | |
43 mask: const [1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1]) | |
Søren Gjesse
2013/06/24 11:02:55
Shouldn't the mask be a bit-mask [OxFF, OxFF, ....
Anders Johnsen
2013/06/24 11:22:19
Done.
| |
44 ]; | |
45 | |
OLD | NEW |