@@ -4,8 +4,11 @@ const fs = std.fs;
44const mem = std .mem ;
55
66const Allocator = std .mem .Allocator ;
7- const File = std .fs .File ;
8- const Dir = std .fs .Dir ;
7+ const Args = std .process .Args ;
8+
9+ const Io = std .Io ;
10+ const File = Io .File ;
11+ const Dir = Io .Dir ;
912
1013const print = std .debug .print ;
1114
@@ -122,9 +125,10 @@ pub const ZonDependencyIterator = struct {
122125 buffer : []const u8 ,
123126 index : usize ,
124127
125- pub fn init (alc : Allocator , file : * const File ) ! ? Self {
126- const stat = try file .stat ();
127- const contents = try file .readToEndAlloc (alc , stat .size );
128+ pub fn init (alc : Allocator , file : * const File , io : Io ) ! ? Self {
129+ const stat = try file .stat (io );
130+ var file_reader = file .reader (io , &.{});
131+ const contents = try file_reader .interface .allocRemaining (alc , .limited (stat .size + 1 ));
128132 const dep_index = mem .indexOf (u8 , contents , ".dependencies" ) orelse return null ;
129133 const start = mem .indexOf (u8 , contents [dep_index .. ], "{" ) orelse return null ;
130134
@@ -166,28 +170,28 @@ pub const ZonFileIterator = struct {
166170 dir : Dir ,
167171 inner_iter : Dir.Walker ,
168172
169- pub fn init (alc : Allocator ) ! Self {
170- var args = std . process . args ();
171- _ = args .skip ();
172- const path = args .next () orelse return error .MissingDirPathArgument ;
173- var dir = try std . fs . cwd ().openDir (path , .{});
173+ pub fn init (alc : Allocator , args : Args , io : Io ) ! Self {
174+ var args_iter = args . iterate ();
175+ _ = args_iter .skip ();
176+ const path = args_iter .next () orelse return error .MissingDirPathArgument ;
177+ var dir = try Dir . cwd ().openDir (io , path , .{ . iterate = true });
174178 return .{
175179 .dir = dir ,
176180 .inner_iter = try dir .walk (alc ),
177181 };
178182 }
179183
180- pub fn deinit (self : * Self ) void {
181- self .dir .close ();
184+ pub fn deinit (self : * Self , io : Io ) void {
185+ self .dir .close (io );
182186 self .inner_iter .deinit ();
183187 }
184188
185- pub fn next (self : * Self ) ! ? File {
186- while (try self .inner_iter .next ()) | entry | {
189+ pub fn next (self : * Self , io : Io ) ! ? File {
190+ while (try self .inner_iter .next (io )) | entry | {
187191 if (entry .kind != File .Kind .file )
188192 continue ;
189193 if (mem .endsWith (u8 , entry .path , ".zon" ))
190- return try self .dir .openFile (entry .path , .{});
194+ return try self .dir .openFile (io , entry .path , .{});
191195 }
192196 return null ;
193197 }
0 commit comments