summaryrefslogtreecommitdiff
path: root/image/png/iend.ha
diff options
context:
space:
mode:
authorLassi Pulkkinen <lassi@pulk.fi>2024-10-31 03:11:21 +0200
committerLassi Pulkkinen <lassi@pulk.fi>2024-10-31 03:51:35 +0200
commitae44478b30d890fe0fb04022f44d474dcdcc3f9d (patch)
tree5f462459ae4b47d22114eed717d1382d08cf4dfe /image/png/iend.ha
Initial commit (import old repo)HEADmain
Diffstat (limited to 'image/png/iend.ha')
-rw-r--r--image/png/iend.ha27
1 files changed, 27 insertions, 0 deletions
diff --git a/image/png/iend.ha b/image/png/iend.ha
new file mode 100644
index 0000000..97651a3
--- /dev/null
+++ b/image/png/iend.ha
@@ -0,0 +1,27 @@
+use bufio;
+use io;
+use memio;
+
+// Reads an IEND chunk from a [[reader]]. This function simply performs a sanity
+// check and verifies the chunk checksum.
+export fn iend_read(src: *reader) (void | error) = {
+ assert(chunk_type(src) == IEND,
+ "Attempted to call iend_read on non-IEND chunk");
+ io::copy(io::empty, src)?;
+};
+
+@test fn iend_reader() void = {
+ const src = memio::fixed(simple_png);
+ const read = newreader(&src) as reader;
+ assert(nextchunk(&read) as u32 == IHDR);
+ io::copy(io::empty, &read)!;
+
+ for (true) {
+ if (nextchunk(&read) as u32 == IEND) {
+ break;
+ };
+ io::copy(io::empty, &read)!;
+ };
+
+ iend_read(&read)!;
+};