import { TextLineStream } from "jsr:@std/streams@1/text-line-stream";
import { ExportEntry } from "./directory-tailer.ts";
import { tailer } from "./main.ts";

export const fullScan = async () => {
  using exports = await Deno.open("./data/exports.jsonl", { read: true });

  // interrupted at 2024-11-12T21:33:47.118Z
  // byte offset
  await exports.seek(13526812085, Deno.SeekMode.Start);

  const lineStream = exports.readable
    .pipeThrough(new TextDecoderStream())
    .pipeThrough(new TextLineStream());

  {
    const reader = lineStream.getReader();
    const line = await reader.read();
    console.log("dropping: " + line.value);
    reader.releaseLock();
  }

  for await (const line of lineStream.values()) {
    const entry = JSON.parse(line) as unknown as ExportEntry;
    await tailer.processRecord(entry, line);
  }
};

await fullScan();