abstract class Bakelite::Item

Overview

Abstract representation of an embedded or stored virtual file.

Direct Known Subclasses

Defined in:

bakelite/item.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(path : String, volume_name : Symbol | String, size : Int64, compressed_size : Int64, mime_type : String, crc32 : UInt32, storage_mode : StorageMode, sha256 : String | Nil = nil) #

[View source]

Class Method Detail

def self.normalize_sha256(digest : String) : String #

Normalizes a SHA-256 hex digest string (strips optional "sha256:" prefix and downcases).


[View source]

Instance Method Detail

def compressed_size : Int64 #

[View source]
def compute_crc32 : UInt32 #

Recomputes the CRC32 checksum by streaming the uncompressed content.


[View source]
def compute_sha256 : String #

Recomputes the lowercase hex SHA-256 digest by streaming the uncompressed content.


[View source]
def content : String #

Alias for to_s for instant content inspection.


[View source]
def content_address : String #

Returns the canonical deterministic content address URI ("sha256:").


[View source]
def crc32 : UInt32 #

[View source]
def crc32_hex : String #

Hexadecimal formatted CRC32 checksum (e.g. "a1b2c3d4").


[View source]
def etag : String #

HTTP-compliant ETag string based on CRC32 checksum and file size.


[View source]
def extract(target_path : Path | String, overwrite : Bool = true) : Bool #

Extracts this virtual file to a target path on disk.


[View source]
def mime_type : String #

[View source]
abstract def open : IO #

Opens a readable stream for this asset.


[View source]
def open(&block : IO -> T) : T forall T #

Yields an open stream to the block and automatically closes it upon completion.


[View source]
def path : String #

[View source]
def sha256 : String #

Returns the deterministic 64-character lowercase hex SHA-256 digest of the uncompressed content. Lazily computed and cached on first access in O(chunk_size) streaming memory.


[View source]
def sha256_bytes : Bytes #

Returns the 32-byte binary SHA-256 digest of the uncompressed content.


[View source]
def size : Int64 #

[View source]
def storage_mode : StorageMode #

[View source]
def strong_etag : String #

Content-addressed strong HTTP ETag based on SHA-256 digest.


[View source]
abstract def to_s(io : IO) : Nil #

Streams the content into the given output IO.


[View source]
def to_s : String #

Returns the content as a UTF-8 String.


[View source]
abstract def to_slice : Bytes #

Returns the full contents as a byte slice.


[View source]
def verify_crc32? : Bool #

Verifies that the freshly streamed CRC32 checksum matches the recorded metadata crc32.


[View source]
def verify_sha256?(expected_digest : String) : Bool #

Verifies that the freshly streamed SHA-256 digest matches the expected digest.


[View source]
def volume_name : String #

[View source]