36 lines
		
	
	
	
		
			1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
	
		
			1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| 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 (fromByteOffset?: number) => {
 | |
|   using exports = await Deno.open("./data/exports.jsonl", { read: true });
 | |
| 
 | |
|   if (fromByteOffset) {
 | |
|     await exports.seek(fromByteOffset, Deno.SeekMode.Start);
 | |
|   }
 | |
| 
 | |
|   const lineStream = exports.readable
 | |
|     .pipeThrough(new TextDecoderStream())
 | |
|     .pipeThrough(new TextLineStream());
 | |
| 
 | |
|   if (fromByteOffset) {
 | |
|     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);
 | |
|   }
 | |
| };
 | |
| 
 | |
| if (import.meta.main) {
 | |
|   const fromByteOffsetStr = Deno.args.at(0);
 | |
|   const fromByteOffset = fromByteOffsetStr
 | |
|     ? parseInt(fromByteOffsetStr)
 | |
|     : undefined;
 | |
| 
 | |
|   await fullScan(fromByteOffset);
 | |
| }
 |