diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2026-04-10 22:09:15 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2026-04-10 22:09:15 +0800 |
| commit | 714acb5a1500239e6c968254ba4448c35e047c8f (patch) | |
| tree | b1d67add47ff86c0892ab4d7ddb7fb05213f7fd7 | |
| parent | 35b9a686cb8c5473ad756f49ee293d8ed23e34e8 (diff) | |
| download | cvn-714acb5a1500239e6c968254ba4448c35e047c8f.tar.gz | |
wip: index streamer.
| -rw-r--r-- | vcx | 32 |
1 files changed, 27 insertions, 5 deletions
@@ -329,7 +329,7 @@ sub hash_file_content { return $sha->hexdigest; } -sub get_dir_scanner { +sub dir_streamer { my (@paths) = @_; my $chunk_size = 1024 * 64; # 64 KB chunks for IO buffering @@ -352,13 +352,12 @@ sub get_dir_scanner { print $tmp_fh @buf; @buf = (); $buf_size = 0; - } + }; my @stack = @paths; while (@stack) { my $path = (pop @stack) =~ s|^\./||r; my @st = lstat($path); - if (-d _) { if (opendir(my $dh, $path)) { push @stack, map { File::Spec->catfile($path, $_) } @@ -394,7 +393,7 @@ sub get_dir_scanner { chomp $line; my ($p, $s, $m) = split(/\t/, $line); return { path => $p, size => $s, mtime => $m }; - } + }; } else { $flush->() if @buffer; # Clear remaining close $tmp_fh; @@ -412,6 +411,29 @@ sub get_dir_scanner { chomp $line; my ($p, $s, $m) = split(/\t/, $line); return { path => $p, size => $s, mtime => $m }; - } + }; } } + +sub index_streamer { + $index = INDEX; + open(my $fh, "<:utf8", $index) or die "Could not open index: $!"; + + return sub { + my $line = <$fh>; + unless (defined $line) { + close $fh; + return; + } + + chomp $line; + my ($path, $size, $mtime, $hash) = split(/\t/, $line); + + return { + path => $path, + size => $size, + mtime => $mtime, + hash => $hash, + }; + }; +} |
