class FsCache::Attributes::Crc

CRC attribute. Can be:

Constants

CRC_BLOCK_SIZE

Size of blocks to compute CRCs in bytes. Changing this value will invalidate previously computed CRCs.

Public Instance Methods

attribute_for(file) click to toggle source

Get the attribute for a given file

Parameters
  • file (String): File to get the attribute for

Result
  • Object: Corresponding attribute value

# 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() click to toggle source

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

# File lib/fs_cache/attributes/crc.rb, line 36
def invalidated_on_change_of
  [:size]
end