SquashFS compressed filesystem reader in pure OCaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ocaml-squashfs: enable MDX on lib/squashfs_writer.mli

Run mdx on lib/squashfs_writer.mli so the {[ ... ]} odoc blocks now
type-check.

The Example used absolute paths ("/", "/bin", "/bin/hello"), but the
writer's own security-considerations note says it "Rejects absolute
paths and paths containing ..". The image build would have raised at
runtime. Switched to relative paths, which is also what the test
suite uses, and added an `assert (String.length image > 0)` so the
example actually documents that finalize produces bytes.

Used Squashfs.Writer.* (the canonical re-export from squashfs.mli)
instead of Squashfs_writer.* throughout, so the example reads as a
user would write it.

The Compression block called `finalize` on a Zstd-configured writer.
The library only implements Gzip -- finalize on Zstd raises
"only gzip compression is currently supported". Wrapped the Zstd
example in `let make_zstd () = ...` so the example shows the API
shape (Squashfs.Writer.Zstd is a real constructor) without invoking
the unsupported codec at mdx test time.

+20 -10
+4
lib/dune
··· 2 2 (name squashfs) 3 3 (public_name squashfs) 4 4 (libraries bytesrw bytesrw.zlib bytesrw.zstd eio fmt wire)) 5 + 6 + (mdx 7 + (files squashfs_writer.mli) 8 + (libraries squashfs))
+16 -10
lib/squashfs_writer.mli
··· 11 11 {2 Example} 12 12 13 13 {[ 14 - (* Create a simple squashfs image *) 15 - let fs = Squashfs_writer.v () in 16 - Squashfs_writer.add_directory fs "/" ~mode:0o755; 17 - Squashfs_writer.add_directory fs "/bin" ~mode:0o755; 18 - Squashfs_writer.add_file fs "/bin/hello" ~mode:0o755 19 - "#!/bin/sh\necho Hello\n"; 20 - Squashfs_writer.add_symlink fs "/bin/hi" "/bin/hello"; 21 - let image = Squashfs_writer.finalize fs in 22 - (* image is a string containing the squashfs data *) 14 + (* Create a simple squashfs image. Paths are relative -- absolute paths 15 + and ".." are rejected (see {!section-Security_Considerations}). *) 16 + let fs = Squashfs.Writer.v () 17 + let () = Squashfs.Writer.add_directory fs "bin" ~mode:0o755 18 + let () = 19 + Squashfs.Writer.add_file fs "bin/hello" ~mode:0o755 20 + "#!/bin/sh\necho Hello\n" 21 + let () = Squashfs.Writer.add_symlink fs "bin/hi" "bin/hello" 22 + let image = Squashfs.Writer.finalize fs 23 + let () = assert (String.length image > 0) 23 24 ]} 24 25 25 26 {2 Compression} ··· 28 29 selected at creation time: 29 30 30 31 {[ 31 - let fs = Squashfs_writer.v ~compression:Squashfs.Zstd () in 32 + (* Only [Gzip] is currently implemented; the others are accepted 33 + by [v] but raise on [finalize]. *) 34 + let make_zstd () = 35 + let fs = Squashfs.Writer.v ~compression:Squashfs.Writer.Zstd () in 36 + Squashfs.Writer.add_file fs "data" ~mode:0o644 "payload"; 37 + Squashfs.Writer.finalize fs 32 38 ]} 33 39 34 40 {2 Security Considerations}