diff options
Diffstat (limited to 'image/png/iend.ha')
-rw-r--r-- | image/png/iend.ha | 27 |
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)!; +}; |