class ICFS::StoreS3

Permanent store for items using AWS S3

Public Class Methods

new(client, bucket, prefix=nil) click to toggle source

New store

@param client [Aws::S3::Client] The configured S3 client @param bucket [String] The bucket name @param prefix [String] Prefix to use for object keys

# File lib/icfs/store_s3.rb, line 32
def initialize(client, bucket, prefix=nil)
  @s3 = client
  @bck = bucket
  @base = prefix || ''
end

Public Instance Methods

file_read(cid, enum, lnum, fnum) click to toggle source

(see Store#file_read)

# File lib/icfs/store_s3.rb, line 42
def file_read(cid, enum, lnum, fnum)
  tmp = tempfile
  key = _file(cid, enum, lnum, fnum)
  @s3.get_object( bucket: @bck, key: key, response_target: tmp)
  tmp.rewind
  return tmp
rescue Aws::S3::Errors::NoSuchKey
  return nil
end
file_size(cid, enum, lnum, fnum) click to toggle source

(see Store#file_size)

# File lib/icfs/store_s3.rb, line 71
def file_size(cid, enum, lnum, fnum)
  key = _file(cid, enum, lnum, fnum)
  resp = @s3.head_object( bucket: @bck, key: key )
  return resp.content_length
rescue Aws::S3::Errors::NotFound
  return nil
end
file_write(cid, enum, lnum, fnum, tmpf) click to toggle source

(see Store#file_write)

# File lib/icfs/store_s3.rb, line 56
def file_write(cid, enum, lnum, fnum, tmpf)
  key = _file(cid, enum, lnum, fnum)
  tmpf.rewind
  @s3.put_object( bucket: @bck, key: key, body: tmpf )

  if tmpf.respond_to?( :close! )
    tmpf.close!
  else
    tmpf.close
  end
end
tempfile() click to toggle source

(see Store#tempfile)

# File lib/icfs/store_s3.rb, line 83
def tempfile
  Tempfile.new('tmp', encoding: 'ascii-8bit')
end

Private Instance Methods

_read(path) click to toggle source

(see Store#_read)

# File lib/icfs/store_s3.rb, line 94
def _read(path)
  @s3.get_object( bucket: @bck, key: path).body.read
rescue Aws::S3::Errors::NoSuchKey
  return nil
end
_write(path, item) click to toggle source

(see Store#_write)

# File lib/icfs/store_s3.rb, line 104
def _write(path, item)
  @s3.put_object( bucket: @bck, key: path, body: item )
end