OCAMLPACKS[] =
extlib
oUnit
+ gz
UseCamlp4(pa_oo pa_field)
xml-light
oUnit
str
+ gz
FILES[] =
label
OUnitTest(cpool , cpool revList)
OUnitTest(swfOut, swfOut swfBaseOut bitsOut)
-OUnitTest(swfIn, swfIn swfBaseIn bitsIn swfOut swfBaseOut bitsOut)
+OUnitTest(swfIn, swfIn swfBaseIn bitsIn swfOut swfBaseOut bitsOut bytesIn)
OUnitTest(tagOut, tagOut tagType)
OUnitTest(tagIn, tagIn swfBaseIn bitsIn tagType swfBaseOut bitsOut)
OUnitTest(swfBaseOut, swfBaseOut bitsOut)
open TagOut
type t = Abc.t TagType.t SwfType.t
+exception SwfError of string
module Writer = SwfOut.Make(TagOut.Make(Abc))
module Reader = SwfIn.Make(TagIn.Make(Abc))
+> List.iter (output_byte ch)
let read ch =
- BytesIn.of_channel ch
- +> Reader.read
+ try
+ BytesIn.of_channel ch
+ +> Reader.read
+ with e ->
+ raise (SwfError (Printexc.to_string e))
[< (tag,size) = tag_and_size; body = repeat size ui8 >] ->
Tag.read tag @@ Stream.of_list body
- let read = parser
- [< _ = char 'F'; _ = char 'W'; _ = char 'S';
- version = ui8; _ = ui32; (left,right,top,bottom) = rect;
+ let swf = parser
+ [< version = ui8; _ = ui32; (left,right,top,bottom) = rect;
frame_rate = fixed8; frame_count = ui16; tags = many to_tag >] ->
{
version;
frame_count;
tags
}
+
+ let string_of_stream stream =
+ let buf =
+ Buffer.create 0 in
+ Stream.iter (Buffer.add_char buf $ char_of_int) stream;
+ Buffer.contents buf
+
+ let stream_of_string s =
+ let n =
+ String.length s in
+ Stream.from begin fun i ->
+ if i < n then
+ Some (int_of_char s.[i])
+ else
+ None
+ end
+
+ let uncompress s =
+ String.iter (fun c -> Printf.printf "[%x]\n" (int_of_char c)) s(*;
+ Gz.uncompress s ~pos:0 ~len:(String.length s)*)
+ ;s
+
+ let read stream =
+ match stream with parser
+ [< _ = char 'F'; _ = char 'W'; _ = char 'S' >] ->
+ swf stream
+ | [< _ = char 'C'; _ = char 'W'; _ = char 'S' >] ->
+ string_of_stream stream
+ +> uncompress
+ +> stream_of_string
+ +> swf
end
assert_equal ?msg (SwfBaseOut.to_list y) (SwfBaseOut.to_list (f x))
let _ = begin "swfIn.ml" >::: [
+ "compress" >:: begin fun () ->
+ open_in_with "compress.swf" begin fun ch ->
+ ignore @@ M.read @@ BytesIn.of_channel ch
+ end
+ end;
"header" >:: begin fun () ->
let swf = {
version = 9;