@zigc/lib 0.17.0-dev.702 → 0.17.0-dev.704
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/std/Io/Reader.zig +10 -4
- package/std/Io/Writer.zig +26 -7
package/package.json
CHANGED
package/std/Io/Reader.zig
CHANGED
|
@@ -226,10 +226,16 @@ pub fn streamExact64(r: *Reader, w: *Writer, n: u64) StreamError!void {
|
|
|
226
226
|
|
|
227
227
|
/// "Pump" exactly `n` bytes from the reader to the writer.
|
|
228
228
|
///
|
|
229
|
-
///
|
|
230
|
-
/// buffered.
|
|
231
|
-
///
|
|
232
|
-
///
|
|
229
|
+
/// On success, at least `preserve_len` bytes will remain buffered if there are
|
|
230
|
+
/// enough buffered bytes to do so.
|
|
231
|
+
/// The amount buffered by the writer after the call will only be less than
|
|
232
|
+
/// `preserve_len` if `w.end + n` is less than `preserve_len` before the call.
|
|
233
|
+
/// The intentionally preserved bytes will include up to `preserve_len -| n` bytes from
|
|
234
|
+
/// the previously buffered bytes, plus `@min(n, preserve_len)` of the newly
|
|
235
|
+
/// "pumped" bytes.
|
|
236
|
+
///
|
|
237
|
+
/// Asserts `Writer.buffer` capacity is at least `preserve_len`.
|
|
238
|
+
/// `n` can be greater than the `Writer.buffer` capacity.
|
|
233
239
|
pub fn streamExactPreserve(r: *Reader, w: *Writer, preserve_len: usize, n: usize) StreamError!void {
|
|
234
240
|
if (w.end + n <= w.buffer.len) {
|
|
235
241
|
@branchHint(.likely);
|
package/std/Io/Writer.zig
CHANGED
|
@@ -417,7 +417,8 @@ pub fn writableSliceGreedyPreserve(w: *Writer, preserve: usize, minimum_len: usi
|
|
|
417
417
|
return w.buffer[w.end..];
|
|
418
418
|
}
|
|
419
419
|
|
|
420
|
-
/// Asserts the provided buffer has total capacity enough for `len
|
|
420
|
+
/// Asserts the provided buffer has total capacity enough for `len`
|
|
421
|
+
/// and `preserve` combined.
|
|
421
422
|
///
|
|
422
423
|
/// Advances the buffer end position by `len`.
|
|
423
424
|
///
|
|
@@ -755,8 +756,14 @@ pub fn writeByte(w: *Writer, byte: u8) Error!void {
|
|
|
755
756
|
}
|
|
756
757
|
}
|
|
757
758
|
|
|
758
|
-
///
|
|
759
|
-
///
|
|
759
|
+
/// On success, at least `preserve` bytes will remain buffered if there are
|
|
760
|
+
/// enough buffered bytes to do so.
|
|
761
|
+
/// The amount buffered by the writer after the call will only be less than
|
|
762
|
+
/// `preserve` if `w.end + 1` is less than `preserve` before the call.
|
|
763
|
+
/// The intentionally preserved bytes will include up to `preserve -| 1` bytes from
|
|
764
|
+
/// the previously buffered bytes, plus the newly written byte.
|
|
765
|
+
///
|
|
766
|
+
/// Asserts buffer capacity is at least `preserve`.
|
|
760
767
|
pub fn writeBytePreserve(w: *Writer, preserve: usize, byte: u8) Error!void {
|
|
761
768
|
if (w.buffer.len - w.end != 0) {
|
|
762
769
|
@branchHint(.likely);
|
|
@@ -784,6 +791,19 @@ test splatByteAll {
|
|
|
784
791
|
try testing.expectEqualStrings(&@as([45]u8, @splat('7')), aw.writer.buffered());
|
|
785
792
|
}
|
|
786
793
|
|
|
794
|
+
/// Writes the same byte many times, performing the underlying write call as
|
|
795
|
+
/// many times as necessary.
|
|
796
|
+
///
|
|
797
|
+
/// On success, at least `preserve` bytes will remain buffered if there are
|
|
798
|
+
/// enough buffered bytes to do so.
|
|
799
|
+
/// The amount buffered by the writer after the call will only be less than
|
|
800
|
+
/// `preserve` if `w.end + n` is less than `preserve` before the call.
|
|
801
|
+
/// The intentionally preserved bytes will include up to `preserve -| n` bytes from
|
|
802
|
+
/// the previously buffered bytes, plus `@min(n, preserve_len)` of the newly
|
|
803
|
+
/// written bytes.
|
|
804
|
+
///
|
|
805
|
+
/// Asserts buffer capacity is at least `preserve`.
|
|
806
|
+
/// `n` can be greater than the buffer capacity.
|
|
787
807
|
pub fn splatBytePreserve(w: *Writer, preserve: usize, byte: u8, n: usize) Error!void {
|
|
788
808
|
const new_end = w.end + n;
|
|
789
809
|
if (new_end <= w.buffer.len) {
|
|
@@ -2504,15 +2524,14 @@ pub fn Hashing(comptime Hasher: type) type {
|
|
|
2504
2524
|
|
|
2505
2525
|
fn drain(w: *Writer, data: []const []const u8, splat: usize) Error!usize {
|
|
2506
2526
|
const this: *@This() = @alignCast(@fieldParentPtr("writer", w));
|
|
2507
|
-
|
|
2508
|
-
hasher.update(w.buffered());
|
|
2527
|
+
this.hasher.update(w.buffered());
|
|
2509
2528
|
w.end = 0;
|
|
2510
2529
|
var n: usize = 0;
|
|
2511
2530
|
for (data[0 .. data.len - 1]) |slice| {
|
|
2512
|
-
hasher.update(slice);
|
|
2531
|
+
this.hasher.update(slice);
|
|
2513
2532
|
n += slice.len;
|
|
2514
2533
|
}
|
|
2515
|
-
for (0..splat) |_| hasher.update(data[data.len - 1]);
|
|
2534
|
+
for (0..splat) |_| this.hasher.update(data[data.len - 1]);
|
|
2516
2535
|
return n + splat * data[data.len - 1].len;
|
|
2517
2536
|
}
|
|
2518
2537
|
};
|