module

Memo::Files

File indexing support for memo CLI

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

Instance methods

binary?(path : String) : Bool

Check if file is binary using libmagic

Source
binary_by_content?(path : String, sample_size : Int32 = 8192) : Bool

Fallback binary detection by checking for null bytes

Source
collect(root : String, ignore_file : String = ".gitignore") : Array(String)

Collect all text files in directory

Source
content_hash(path : String) : Bytes

Compute SHA256 hash of file content

Source
count(db : DB::Database) : Int64

Count indexed files

Source
delete(db : DB::Database, source_id : Int64) : Bool

Delete file record

Source
file_info(path : String, root : String) : FileInfo

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

Source
get_by_hash(db : DB::Database, hash : Bytes) : FileRecord | Nil

Get file record by content hash

Source
get_by_path(db : DB::Database, path : String) : FileRecord | Nil

Get file record by path

Source
get_by_source(db : DB::Database, source_id : Int64) : FileRecord | Nil

Get file record by source_id

Source
list(db : DB::Database, limit : Int32 = 100, offset : Int32 = 0) : Array(FileRecord)

List all indexed files

Source
needs_update?(record : FileRecord, current_mtime : Int64) : Bool

Check if file needs re-indexing (mtime changed)

Source
store(db : DB::Database, source_id : Int64, info : FileInfo)

Store file record in database

Source
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")
Source

Nested types