Class: FsCache::Attributes::Crc
- Inherits:
-
FsCache::Attribute
- Object
- FsCache::Attribute
- FsCache::Attributes::Crc
- Defined in:
- lib/fs_cache/attributes/crc.rb
Overview
CRC attribute. Can be:
-
String: Internal CRC computed from files by blocks
Defined Under Namespace
Modules: Helpers
Constant Summary collapse
- CRC_BLOCK_SIZE =
Size of blocks to compute CRCs in bytes. Changing this value will invalidate previously computed CRCs.
32 * 1024 * 1024
Instance Method Summary collapse
-
#attribute_for(file) ⇒ Object
Get the attribute for a given file.
-
#invalidated_on_change_of ⇒ Object
Get the list of other attributes that invalidate this one.
Instance Method Details
#attribute_for(file) ⇒ Object
Get the attribute for a given file
- Parameters
-
file (String): File to get the attribute for
- Result
-
Object: Corresponding attribute value
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fs_cache/attributes/crc.rb', line 20 def attribute_for(file) blocks_crc = '' File.open(file, 'rb') do |file_io| buffer = nil while (buffer = file_io.read(CRC_BLOCK_SIZE)) blocks_crc << Zlib.crc32(buffer, 0).to_s(16).upcase end end Zlib.crc32(blocks_crc, 0).to_s(16).upcase end |
#invalidated_on_change_of ⇒ Object
Get the list of other attributes that invalidate this one. If any of those attributes is chaning on a file, then reset our attribute for the file.
- Result
-
Array<Symbol>: List of dependent attributes
36 37 38 |
# File 'lib/fs_cache/attributes/crc.rb', line 36 def invalidated_on_change_of [:size] end |