Sha256: 6fa00b44e689bc4b3504589f2761e4b52fd1138a83b78b0bf38e0a80a50aa9f4
Contents?: true
Size: 829 Bytes
Versions: 1
Compression:
Stored size: 829 Bytes
Contents
class CompactIndexClient class Updater attr_reader :fetcher def initialize(fetcher) @fetcher = fetcher end def update(local_path, remote_path) headers = {} if local_path.file? headers["If-None-Match"] = checksum_for_file(local_path) headers["Range"] = "bytes=#{local_path.size}-" end response = fetcher.call(remote_path, headers) return if response.is_a?(Net::HTTPNotModified) mode = response.is_a?(Net::HTTPPartialContent) ? "a" : "w" local_path.open(mode) {|f| f << response.body } return if checksum_for_file(local_path) == response["ETag"] local_path.delete update(local_path, remote_path) end def checksum_for_file(path) return nil unless path.file? Digest::MD5.file(path).hexdigest end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
compact_index_client-0.1.0 | lib/compact_index_client/updater.rb |