I can't manage to do this using Leage\Csv\Read
for some reason. The CSV starts from an arbitrary point.
This is why I made this.
$s3 = new S3Client([...]);
$s3->registerStreamWrapper();
$stream = fopen("s3://{$bucket}/{$path}", 'r');
if (!is_resource($stream)) {
throw new RuntimeException('Could not stream the csv');
}
$csv = new ChunkCsvReader($stream, chunkSize: 1_000);
$iterator = $csv->iterator();
foreach ($iterator as $chunk) {
dump('Memory usage in kb: ' . memory_get_usage(true) / 1024);
foreach ($chunk as $item) {
dump($item['id'] - $item['type']);
}
}