| ... | @@ -2786,8 +2786,6 @@ pub const Zld = struct { | ... | @@ -2786,8 +2786,6 @@ pub const Zld = struct { |
| 2786 | var hashed: usize = 0; | 2786 | var hashed: usize = 0; |
| 2787 | | 2787 | |
| 2788 | for (subsections[0..count]) |cut| { | 2788 | for (subsections[0..count]) |cut| { |
| 2789 | // std.debug.print("{x} - {x}, {x}\n", .{ cut.start, cut.end, cut.end - cut.start }); | | |
| 2790 | | | |
| 2791 | const size = cut.end - cut.start; | 2789 | const size = cut.end - cut.start; |
| 2792 | const num_chunks = mem.alignForward(size, chunk_size) / chunk_size; | 2790 | const num_chunks = mem.alignForward(size, chunk_size) / chunk_size; |
| 2793 | | 2791 | |
| ... | @@ -2798,12 +2796,9 @@ pub const Zld = struct { | ... | @@ -2798,12 +2796,9 @@ pub const Zld = struct { |
| 2798 | cut.end - fstart | 2796 | cut.end - fstart |
| 2799 | else | 2797 | else |
| 2800 | chunk_size; | 2798 | chunk_size; |
| 2801 | // std.debug.print("fstart {x}, fsize {x}\n", .{ fstart, fsize }); | | |
| 2802 | const amt = try self.file.preadAll(buffer[0..fsize], fstart); | 2799 | const amt = try self.file.preadAll(buffer[0..fsize], fstart); |
| 2803 | if (amt != fsize) return error.InputOutput; | 2800 | if (amt != fsize) return error.InputOutput; |
| 2804 | | 2801 | |
| 2805 | // try formatBinaryBlob(buffer[0..fsize], .{ .fmt_as_str = false }, std.io.getStdOut().writer()); | | |
| 2806 | | | |
| 2807 | var leftover = rb.append(buffer[0..fsize]); | 2802 | var leftover = rb.append(buffer[0..fsize]); |
| 2808 | while (leftover > 0) { | 2803 | while (leftover > 0) { |
| 2809 | if (rb.full()) { | 2804 | if (rb.full()) { |
| ... | @@ -2817,14 +2812,11 @@ pub const Zld = struct { | ... | @@ -2817,14 +2812,11 @@ pub const Zld = struct { |
| 2817 | } | 2812 | } |
| 2818 | | 2813 | |
| 2819 | if (!rb.empty()) { | 2814 | if (!rb.empty()) { |
| 2820 | // try formatBinaryBlob(rb.getBuffer(), .{ .fmt_as_str = false }, std.io.getStdOut().writer()); | | |
| 2821 | hasher.update(rb.getBuffer()); | 2815 | hasher.update(rb.getBuffer()); |
| 2822 | hashed += rb.getBuffer().len; | 2816 | hashed += rb.getBuffer().len; |
| 2823 | rb.clear(); | 2817 | rb.clear(); |
| 2824 | } | 2818 | } |
| 2825 | | 2819 | |
| 2826 | // std.debug.print("hashed {x}\n", .{hashed}); | | |
| 2827 | | | |
| 2828 | hasher.final(&self.uuid_cmd.uuid); | 2820 | hasher.final(&self.uuid_cmd.uuid); |
| 2829 | conformUuid(&self.uuid_cmd.uuid); | 2821 | conformUuid(&self.uuid_cmd.uuid); |
| 2830 | }, | 2822 | }, |
| ... | @@ -2834,38 +2826,6 @@ pub const Zld = struct { | ... | @@ -2834,38 +2826,6 @@ pub const Zld = struct { |
| 2834 | try self.file.pwriteAll(&self.uuid_cmd.uuid, in_file); | 2826 | try self.file.pwriteAll(&self.uuid_cmd.uuid, in_file); |
| 2835 | } | 2827 | } |
| 2836 | | 2828 | |
| 2837 | const FmtBinaryBlobOpts = struct { | | |
| 2838 | fmt_as_str: bool = true, | | |
| 2839 | escape_str: bool = false, | | |
| 2840 | }; | | |
| 2841 | | | |
| 2842 | fn formatBinaryBlob(blob: []const u8, opts: FmtBinaryBlobOpts, writer: anytype) !void { | | |
| 2843 | // Format as 16-by-16-by-8 with two left column in hex, and right in ascii: | | |
| 2844 | // xxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxx xxxxxxxx | | |
| 2845 | var i: usize = 0; | | |
| 2846 | const step = 16; | | |
| 2847 | var tmp_buf: [step]u8 = undefined; | | |
| 2848 | while (i < blob.len) : (i += step) { | | |
| 2849 | const end = if (blob[i..].len >= step) step else blob[i..].len; | | |
| 2850 | const padding = step - blob[i .. i + end].len; | | |
| 2851 | if (padding > 0) { | | |
| 2852 | mem.set(u8, &tmp_buf, 0); | | |
| 2853 | } | | |
| 2854 | mem.copy(u8, &tmp_buf, blob[i .. i + end]); | | |
| 2855 | try writer.print("{x} {x:<016} {x:<016}", .{ | | |
| 2856 | i, std.fmt.fmtSliceHexLower(tmp_buf[0 .. step / 2]), std.fmt.fmtSliceHexLower(tmp_buf[step / 2 .. step]), | | |
| 2857 | }); | | |
| 2858 | if (opts.fmt_as_str) { | | |
| 2859 | if (opts.escape_str) { | | |
| 2860 | try writer.print(" {s}", .{std.fmt.fmtSliceEscapeLower(tmp_buf[0..step])}); | | |
| 2861 | } else { | | |
| 2862 | try writer.print(" {s}", .{tmp_buf[0..step]}); | | |
| 2863 | } | | |
| 2864 | } | | |
| 2865 | try writer.writeByte('\n'); | | |
| 2866 | } | | |
| 2867 | } | | |
| 2868 | | | |
| 2869 | const RingBuffer = struct { | 2829 | const RingBuffer = struct { |
| 2870 | buffer: [chunk_size]u8 = undefined, | 2830 | buffer: [chunk_size]u8 = undefined, |
| 2871 | pos: usize = 0, | 2831 | pos: usize = 0, |
| ... | @@ -2877,12 +2837,9 @@ pub const Zld = struct { | ... | @@ -2877,12 +2837,9 @@ pub const Zld = struct { |
| 2877 | data.len - rb.available() | 2837 | data.len - rb.available() |
| 2878 | else | 2838 | else |
| 2879 | data.len; | 2839 | data.len; |
| 2880 | // std.debug.print(" appending {x} of {x} (pos {x})\n", .{ cpy_size, data.len, rb.pos }); | | |
| 2881 | mem.copy(u8, rb.buffer[rb.pos..], data[0..cpy_size]); | 2840 | mem.copy(u8, rb.buffer[rb.pos..], data[0..cpy_size]); |
| 2882 | rb.pos += cpy_size; | 2841 | rb.pos += cpy_size; |
| 2883 | const leftover = data.len - cpy_size; | 2842 | const leftover = data.len - cpy_size; |
| 2884 | // std.debug.print(" leftover {x}\n", .{leftover}); | | |
| 2885 | // std.debug.print(" buffer {x} full\n", .{rb.pos}); | | |
| 2886 | return leftover; | 2843 | return leftover; |
| 2887 | } | 2844 | } |
| 2888 | | 2845 | |