Class: Bloomfilter::Serialization::S3

Inherits:
Object
  • Object
show all
Defined in:
lib/bloomfilter/serialization/s3.rb

Constant Summary collapse

AWS_SECRET_PATH =
'~/.awssecret'.freeze
TEMP_FILE_PREFIX =
'bloomfilter'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(s3_service, bucket_name) ⇒ S3

Returns a new instance of S3.



10
11
12
13
# File 'lib/bloomfilter/serialization/s3.rb', line 10

def initialize(s3_service, bucket_name)
  @file_serializer = File.new
  @bucket = s3_service.bucket(bucket_name)
end

Instance Method Details

#load(path) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/bloomfilter/serialization/s3.rb', line 33

def load(path)
  s3_object = @bucket.get(path)
  return nil if s3_object.nil?
  begin
    @loaded_file = Marshal.load(s3_object.data)
  rescue Exception => e
    nil
  end
end

#store(path, filter) ⇒ Object



26
27
28
29
30
31
# File 'lib/bloomfilter/serialization/s3.rb', line 26

def store(path, filter)
  begin
    data = Marshal.dump(filter).to_java_bytes
    @bucket.put_data(path, data)
  end
end

#store_file(path, file_path) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/bloomfilter/serialization/s3.rb', line 15

def store_file(path, file_path)
  begin
    file = ::File.new(file_path)
    path.slice!(0) if path[0] == '/'
    @bucket.put(path, file)
  rescue Exception => e
    $stderr.puts "Exception when storing to S3 #{e.message}"
    $stderr.puts e.backtrace
  end
end