1 /*
2     This file is part of BioD.
3     Copyright (C) 2012-2016    Artem Tarasov <lomereiter@gmail.com>
4 
5     Permission is hereby granted, free of charge, to any person obtaining a
6     copy of this software and associated documentation files (the "Software"),
7     to deal in the Software without restriction, including without limitation
8     the rights to use, copy, modify, merge, publish, distribute, sublicense,
9     and/or sell copies of the Software, and to permit persons to whom the
10     Software is furnished to do so, subject to the following conditions:
11 
12     The above copyright notice and this permission notice shall be included in
13     all copies or substantial portions of the Software.
14 
15     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21     DEALINGS IN THE SOFTWARE.
22 
23 */
24 module bio.core.bgzf.constants;
25 
26 immutable ubyte[4] BGZF_MAGIC = [0x1F, 0x8B, 0x8, 0x4];
27 
28 immutable ubyte[16] BLOCK_HEADER_START =
29     [ 31, 139,   8,   4,  // BGZF magic
30        0,   0,   0,   0,  // GZIP modification time
31        0,                 // GZIP extra flags
32      255,                 // GZIP OS identifier
33        6,   0,            // GZIP extra length == 6 (LE)
34       66,  67,            // Subfield 'BC'
35        2,   0];           // Subfield length (holds 1 ushort)
36 
37 // empty block
38 immutable ubyte[28] BGZF_EOF =
39     [31, 139, 8, 4,
40         0, 0, 0, 0,
41                  0,
42                255,
43               6, 0,
44             66, 67,
45               2, 0,
46              27, 0,
47               3, 0,
48         0, 0, 0, 0,
49         0, 0, 0, 0];
50 
51 
52 
53 // BGZF block header length in bytes.
54 // Block header holds BLOCK_HEADER_START + block size (ushort)
55 immutable BLOCK_HEADER_LENGTH = BLOCK_HEADER_START.length + ushort.sizeof;
56 
57 // BGZF footer holds CRC32 and size of decompressed block.
58 immutable BLOCK_FOOTER_LENGTH = uint.sizeof + uint.sizeof;
59 
60 immutable BGZF_MAX_BLOCK_SIZE = 65536;
61 immutable BGZF_BLOCK_SIZE = 0xFF00;