mirror of
https://github.com/tsolomko/SWCompression.git
synced 2026-06-23 14:56:41 +00:00
Added parsing magic number of bzip2 archives.
This commit is contained in:
@@ -17,6 +17,7 @@ import Foundation
|
||||
- `WrongBlockType`: unsupported block type (not 'pi' or 'sqrt(pi)').
|
||||
*/
|
||||
public enum BZip2Error: Error {
|
||||
case WrongMagic
|
||||
/// Compression method was not type 'h' (not Huffman).
|
||||
case WrongCompressionMethod
|
||||
/// Unknown block size (not from '0' to '9').
|
||||
@@ -51,6 +52,8 @@ public class BZip2: DecompressionAlgorithm {
|
||||
|
||||
/// Object with input data which supports convenient work with bit shifts.
|
||||
let pointerData = DataWithPointer(data: data)
|
||||
let magic = pointerData.intFromBits(count: 16)
|
||||
guard magic == 0x425a else { throw BZip2Error.WrongMagic }
|
||||
|
||||
let method = pointerData.intFromBits(count: 8)
|
||||
guard method == 104 else { throw BZip2Error.WrongCompressionMethod }
|
||||
|
||||
Reference in New Issue
Block a user