@@ -17,9 +17,7 @@ pub fn main() !void {
1717 const patch_file = patch_file : {
1818 const patch_file = try std .fs .cwd ().openFile (patch_file_path , .{ .mode = .read_only });
1919 defer patch_file .close ();
20- var patch_buf : [4096 ]u8 = undefined ;
21- var reader = patch_file .reader (& patch_buf );
22- break :patch_file try reader .interface .allocRemaining (allocator , .unlimited );
20+ break :patch_file try patch_file .readToEndAlloc (allocator , std .math .maxInt (usize ));
2321 };
2422 const chunk_details = Chunk .init (allocator , patch_file , 0 ) orelse @panic ("No chunk data found" );
2523
@@ -41,35 +39,26 @@ pub fn main() !void {
4139
4240 switch (state ) {
4341 .copy = > {
44- _ = try reader .interface .streamDelimiterEnding (& writer .interface , '\n ' );
45- _ = reader .interface .takeByte () catch | err | switch (err ) {
42+ _ = reader .interface .streamDelimiter (& writer .interface , '\n ' ) catch | err | switch (err ) {
4643 error .EndOfStream = > {
4744 try writer .end ();
4845 return ;
4946 },
5047 else = > return err ,
5148 };
49+ reader .interface .toss (1 );
5250 try writer .interface .writeByte ('\n ' );
5351 },
5452 .chunk = > {
5553 const chunk = chunk_details .lines [line_number - chunk_details .src ];
5654 switch (chunk .action ) {
5755 .remove = > {
58- const line = reader .interface .takeDelimiterExclusive ('\n ' ) catch | err | switch (err ) {
59- error .EndOfStream = > return ,
60- else = > return err ,
61- };
56+ const line = try reader .interface .takeDelimiterExclusive ('\n ' );
6257 if (! std .mem .eql (u8 , chunk .buf , line )) @panic ("Failed to apply patch" );
6358 },
6459 .keep = > {
65- const line = reader .interface .takeDelimiterExclusive ('\n ' ) catch | err | switch (err ) {
66- error .EndOfStream = > return ,
67- else = > return err ,
68- };
69- if (! std .mem .eql (u8 , chunk .buf , line )) {
70- std .debug .print ("exp {s}\n got {s}\n " , .{ chunk .buf , line });
71- @panic ("Failed to apply patch" );
72- }
60+ const line = try reader .interface .takeDelimiterExclusive ('\n ' );
61+ if (! std .mem .eql (u8 , chunk .buf , line )) @panic ("Failed to apply patch" );
7362 try writer .interface .writeAll (line );
7463 try writer .interface .writeByte ('\n ' );
7564 },
@@ -85,14 +74,6 @@ pub fn main() !void {
8574 }
8675}
8776
88- fn getLine (allocator : Allocator , file : File ) ? []u8 {
89- var buffer : [4096 ]u8 = undefined ;
90- return file .reader (& buffer ).readUntilDelimiterAlloc (allocator , '\n ' , std .math .maxInt (usize )) catch | err | switch (err ) {
91- error .EndOfStream = > return null ,
92- else = > @panic ("Error" ),
93- };
94- }
95-
9677const State = enum { copy , chunk };
9778
9879const Chunk = struct {
0 commit comments