Class: DurableHuggingfaceHub::Types::CachedFileInfo

Inherits:
Struct
  • Object
show all
Includes:
Loadable
Defined in:
lib/durable_huggingface_hub/types/cache_info.rb

Overview

Information about a cached file.

Represents a single file in the cache with its metadata.

Examples:

cached_file = CachedFileInfo.new(
  file_path: Pathname.new("/cache/blobs/abc123"),
  size: 1024,
  etag: "abc123",
  commit_hash: "def456",
  last_accessed: Time.now,
  last_modified: Time.now
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#commit_hashString? (readonly)

Git commit hash this file belongs to

Returns:

  • (String, nil)


41
# File 'lib/durable_huggingface_hub/types/cache_info.rb', line 41

attribute :commit_hash, Types::OptionalString.default(nil)

#etagString? (readonly)

ETag of the file (used for cache validation)

Returns:

  • (String, nil)


36
# File 'lib/durable_huggingface_hub/types/cache_info.rb', line 36

attribute :etag, Types::OptionalString

#file_pathPathname (readonly)

Path to the cached file

Returns:

  • (Pathname)


26
# File 'lib/durable_huggingface_hub/types/cache_info.rb', line 26

attribute :file_path, Types::PathnameType

#last_accessedTime? (readonly)

When the file was last accessed

Returns:

  • (Time, nil)


46
# File 'lib/durable_huggingface_hub/types/cache_info.rb', line 46

attribute :last_accessed, Types::OptionalTimestamp.default(nil)

#last_modifiedTime? (readonly)

When the file was last modified

Returns:

  • (Time, nil)


51
# File 'lib/durable_huggingface_hub/types/cache_info.rb', line 51

attribute :last_modified, Types::OptionalTimestamp.default(nil)

#sizeInteger (readonly)

Size of the file in bytes

Returns:

  • (Integer)


31
# File 'lib/durable_huggingface_hub/types/cache_info.rb', line 31

attribute :size, Types::Integer

Instance Method Details

#size_strString

Human-readable size string.

Returns:

  • (String)

    Size formatted as human-readable string (e.g., “1.2 MB”)



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/durable_huggingface_hub/types/cache_info.rb', line 56

def size_str
  units = ["B", "KB", "MB", "GB", "TB"]
  size = self.size.to_f
  unit_index = 0

  while size >= 1024 && unit_index < units.length - 1
    size /= 1024.0
    unit_index += 1
  end

  format("%.2f %s", size, units[unit_index])
end