module Memo::Files

Overview

File indexing support for memo CLI

Provides directory walking with ignore file support, binary file detection, and file metadata tracking for incremental updates.

Extended Modules

Defined in:

memo/files.cr

Instance Method Summary

Instance Method Detail

def binary?(path : String) : Bool #

Check if file is binary using libmagic


[View source]
def binary_by_content?(path : String, sample_size : Int32 = 8192) : Bool #

Fallback binary detection by checking for null bytes


[View source]
def collect(root : String, ignore_file : String = ".gitignore") : Array(String) #

Collect all text files in directory


[View source]
def content_hash(path : String) : Bytes #

Compute SHA256 hash of file content


[View source]
def count(db : DB::Database) : Int64 #

Count indexed files


[View source]
def delete(db : DB::Database, source_id : Int64) : Bool #

Delete file record


[View source]
def file_info(path : String, root : String) : FileInfo #

Get file info (path, hash, mtime, size)


[View source]
def get_by_hash(db : DB::Database, hash : Bytes) : FileRecord | Nil #

Get file record by content hash


[View source]
def get_by_path(db : DB::Database, path : String) : FileRecord | Nil #

Get file record by path


[View source]
def get_by_source(db : DB::Database, source_id : Int64) : FileRecord | Nil #

Get file record by source_id


[View source]
def list(db : DB::Database, limit : Int32 = 100, offset : Int32 = 0) : Array(FileRecord) #

List all indexed files


[View source]
def needs_update?(record : FileRecord, current_mtime : Int64) : Bool #

Check if file needs re-indexing (mtime changed)


[View source]
def store(db : DB::Database, source_id : Int64, info : FileInfo) #

Store file record in database


[View source]
def walk(root : String, ignore_file : String = ".gitignore", &block : String -> ) #

Walk directory and yield text files, respecting ignore patterns

Uses ignoreme for .gitignore-style filtering. Uses magic.cr to detect and skip binary files.

Options:

  • root: Directory to walk
  • ignore_file: Ignore file name (default ".gitignore")

[View source]