class Bosh::Blobstore::LocalClient

Constants

CHUNK_SIZE

Public Class Methods

new(options) click to toggle source
Calls superclass method Bosh::Blobstore::BaseClient::new
# File lib/blobstore_client/local_client.rb, line 8
def initialize(options)
  super(options)
  @blobstore_path = URI(@options[:blobstore_path]).path
  raise "No blobstore path given in options #{@options}" if @blobstore_path.nil?
  FileUtils.mkdir_p(@blobstore_path) unless File.directory?(@blobstore_path)
end

Protected Instance Methods

create_file(id, file) click to toggle source
# File lib/blobstore_client/local_client.rb, line 17
def create_file(id, file)
  id ||= generate_object_id
  dst = object_file_path(id)
  raise BlobstoreError, "object id #{id} is already in use" if File.exist?(dst)
  File.open(dst, 'w') do |fh|
    fh.write(file.read(CHUNK_SIZE)) until file.eof?
  end
  id
end
delete_object(id) click to toggle source
# File lib/blobstore_client/local_client.rb, line 39
def delete_object(id)
  file = object_file_path(id)
  FileUtils.rm(file)
rescue Errno::ENOENT
  raise NotFound, "Blobstore object '#{id}' not found"
end
get_file(id, file) click to toggle source
# File lib/blobstore_client/local_client.rb, line 27
def get_file(id, file)
  src = object_file_path(id)

  begin
    File.open(src, 'r') do |src_fh|
      file.write(src_fh.read(CHUNK_SIZE)) until src_fh.eof?
    end
  end
rescue Errno::ENOENT
  raise NotFound, "Blobstore object '#{id}' not found"
end
object_exists?(oid) click to toggle source
# File lib/blobstore_client/local_client.rb, line 46
def object_exists?(oid)
  File.exist?(object_file_path(oid))
end

Private Instance Methods

object_file_path(oid) click to toggle source
# File lib/blobstore_client/local_client.rb, line 52
def object_file_path(oid)
  File.join(@blobstore_path, oid)
end