Sha256: 20b8e7627d104cbd23ee7989ac365fa8d15cb7ee77864c62c05c8ba359627d22
Contents?: true
Size: 1.26 KB
Versions: 2
Compression:
Stored size: 1.26 KB
Contents
require 'fileutils' require 'time' require 'shuck/bucket' module Shuck class FileStore def initialize(root) @root = root @buckets = [] @bucket_hash = {} Dir[File.join(root,"*")].each do |bucket| bucket_name = File.basename(bucket) bucket_obj = Bucket.new(bucket_name,Time.now,[]) @buckets << bucket_obj @bucket_hash[bucket_name] = bucket_obj end end def buckets @buckets end def get_bucket(bucket) @bucket_hash[bucket] end def create_bucket(bucket) FileUtils.mkdir_p(File.join(@root,bucket)) bucket_obj = Bucket.new(bucket,Time.now,[]) @buckets << bucket_obj @bucket_hash[bucket] = bucket_obj end def get_object(bucket,object) begin io = File.open(File.join(@root,bucket,object),'rb') return io rescue puts $! return nil end end def store_object(bucket,object,request) begin filename = File.join(@root,bucket,object) parent_dir = File.dirname(filename) FileUtils.mkdir_p(parent_dir) File.open(filename,'w') do |f| request.body do |chunk| f << chunk end end rescue puts $! end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
shuck-0.0.4 | lib/shuck/file_store.rb |
shuck-0.0.3 | lib/shuck/file_store.rb |