~sircmpwn/hare-compress

78bfbe24736bcc517bc56672e121f504da8e969b — Alexey Yerin 9 months ago 6c36c07
Use io::readall
2 files changed, 21 insertions(+), 15 deletions(-)

M compress/flate/inflate.ha
M compress/zlib/reader.ha
M compress/flate/inflate.ha => compress/flate/inflate.ha +7 -5
@@ 369,13 369,15 @@ fn next(d: *decompressor) (void | io::EOF | io::error) = {
		d.cnt = 0;
		d.bitbuf = 0;
		let buf: [4]u8 = [0...];
		for (let n = 0z; n < 4) {
			match (io::read(d.in, buf[n..])?) {
			case io::EOF =>
		match (io::readall(d.in, buf[..])) {
		case size => void;
		case io::EOF =>
			return wraperror(inflate_err::EOF);
		case let err: io::error =>
			if (err is io::underread) {
				return wraperror(inflate_err::EOF);
			case let z: size =>
				n += z;
			};
			return err;
		};
		const length = endian::legetu16(buf[..2]);
		if (length != ~endian::legetu16(buf[2..])) {

M compress/zlib/reader.ha => compress/zlib/reader.ha +14 -10
@@ 87,13 87,15 @@ export fn decompress_error(
fn verifysum(s: *reader) (io::EOF | io::error) = {
	let hash: [adler32::SZ]u8 = [0...];

	for (let n = 0z; n < len(hash)) {
		match (io::read(s.source, hash[n..])?) {
		case io::EOF =>
	match (io::readall(s.source, hash)) {
	case size => void;
	case io::EOF =>
		return wraperror(decompress_err::EOF);
	case let err: io::error =>
		if (err is io::underread) {
			return wraperror(decompress_err::EOF);
		case let z: size =>
			n += z;
		};
		return err;
	};

	return if (adler32::sum32(&s.hash) == endian::begetu32(hash)) io::EOF


@@ 120,13 122,15 @@ fn close(s: *io::stream) (void | io::error) = {
// header (2 bytes) before returning.
export fn decompress(src: io::handle) (reader | io::error) = {
	let buf: [2]u8 = [0...];
	for (let n = 0z; n < len(buf)) {
		match (io::read(src, buf[n..])?) {
		case io::EOF =>
	match (io::readall(src, buf)) {
	case size => void;
	case io::EOF =>
		return wraperror(decompress_err::EOF);
	case let err: io::error =>
		if (err is io::underread) {
			return wraperror(decompress_err::EOF);
		case let z: size =>
			n += z;
		};
		return err;
	};
	if (buf[0] & CM != 8) {
		return wraperror(decompress_err::HEADER);