Class: BFS::Bucket::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/bfs/bucket/abstract.rb

Direct Known Subclasses

FS, InMem

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Abstract

Initializes a new bucket

Parameters:

  • opts (Hash) (defaults to: {})

    options

Options Hash (opts):

  • :encoding (String)

    default encoding, default: binary.



9
10
11
# File 'lib/bfs/bucket/abstract.rb', line 9

def initialize(opts={})
  @encoding = opts.delete(:encoding) || Encoding::BINARY
end

Instance Method Details

#closeObject

Closes the underlying connection



78
# File 'lib/bfs/bucket/abstract.rb', line 78

def close; end

#cp(src, dst, opts = {}) ⇒ Object

Copies src to dst

Parameters:

  • src (String)

    The source path.

  • dst (String)

    The destination path.



60
61
62
63
64
65
66
# File 'lib/bfs/bucket/abstract.rb', line 60

def cp(src, dst, opts={})
  open(src, opts) do |r|
    create(dst, opts) do |w|
      IO.copy_stream(r, w)
    end
  end
end

#create(_path, _opts = {}) ⇒ Object

Creates a new file and opens it for writing



24
25
26
# File 'lib/bfs/bucket/abstract.rb', line 24

def create(_path, _opts={})
  raise 'not implemented'
end

#info(_path, _opts = {}) ⇒ Object

Info returns the info for a single file



19
20
21
# File 'lib/bfs/bucket/abstract.rb', line 19

def info(_path, _opts={})
  raise 'not implemented'
end

#ls(_pattern = '**', _opts = {}) ⇒ Object

Lists the contents of a bucket using a glob pattern



14
15
16
# File 'lib/bfs/bucket/abstract.rb', line 14

def ls(_pattern='**', _opts={})
  raise 'not implemented'
end

#mv(src, dst, _opts = {}) ⇒ Object

Moves src to dst

Parameters:

  • src (String)

    The source path.

  • dst (String)

    The destination path.



72
73
74
75
# File 'lib/bfs/bucket/abstract.rb', line 72

def mv(src, dst, _opts={})
  cp(src, dst)
  rm(src)
end

#open(_path, _opts = {}) ⇒ Object

Opens an existing file for reading May raise BFS::FileNotFound



30
31
32
# File 'lib/bfs/bucket/abstract.rb', line 30

def open(_path, _opts={})
  raise 'not implemented'
end

#read(path, opts = {}) ⇒ Object

Shortcut method to read the contents of a file into memory

Parameters:

  • path (String)

    The path to read from.

  • opts (Hash) (defaults to: {})

    Additional options, see #open.



43
44
45
# File 'lib/bfs/bucket/abstract.rb', line 43

def read(path, opts={})
  open(path, opts, &:read)
end

#rm(_path, _opts = {}) ⇒ Object

Deletes a file.



35
36
37
# File 'lib/bfs/bucket/abstract.rb', line 35

def rm(_path, _opts={})
  raise 'not implemented'
end

#write(path, data, opts = {}) ⇒ Object

Shortcut method to write data to path

Parameters:

  • path (String)

    The path to write to.

  • data (String)

    The data to write.

  • opts (Hash) (defaults to: {})

    Additional options, see #create.



52
53
54
# File 'lib/bfs/bucket/abstract.rb', line 52

def write(path, data, opts={})
  create(path, opts) {|f| f.write data }
end