zip recognize
This commit is contained in:
25
lib/archive/archive.ml
Normal file
25
lib/archive/archive.ml
Normal file
@ -0,0 +1,25 @@
|
||||
(** Base archive utitlities *)
|
||||
|
||||
module Zip = Zip
|
||||
module Xz = Xz
|
||||
module Cpio = Cpio
|
||||
|
||||
type t = { file : string; typ : string }
|
||||
|
||||
let is_signature infile signature =
|
||||
(* assume infile pos is 0 *)
|
||||
let accumulator acc s =
|
||||
match In_channel.input_char infile with
|
||||
| None -> false
|
||||
| Some c -> s == c && acc
|
||||
in
|
||||
Bytes.fold_left accumulator true signature
|
||||
|
||||
(** matching common archive signatures *)
|
||||
let from file =
|
||||
let infile = In_channel.open_bin file in
|
||||
(* support for zip file for now *)
|
||||
if is_signature infile Zip.signature then
|
||||
Some { file = file; typ = "zip"; }
|
||||
else
|
||||
None
|
1
lib/archive/cpio.ml
Normal file
1
lib/archive/cpio.ml
Normal file
@ -0,0 +1 @@
|
||||
let signature = Bytes.of_string "\x30\x37\x30\x37\x30\x37"
|
2
lib/archive/xz.ml
Normal file
2
lib/archive/xz.ml
Normal file
@ -0,0 +1,2 @@
|
||||
(* this signature is the stream header signature *)
|
||||
let signature = Bytes.of_string "\xFD\x37\x7A\x58\x5A\x00"
|
@ -10,5 +10,8 @@
|
||||
which has been deprecated or AES
|
||||
*)
|
||||
|
||||
let signature = Bytes.of_string "PK\x00\x00"
|
||||
type t = { file : string; typ : string }
|
||||
|
||||
let signature = Bytes.of_string "PK\x03\x04"
|
||||
|
||||
let from file = { file = file; typ = "zip" }
|
||||
|
Reference in New Issue
Block a user