MogileFS file manipulation client.
Create a new instance that will communicate with these trackers: hosts = %w[192.168.1.69:6001 192.168.1.70:6001] mg = MogileFS::MogileFS.new(:domain => 'test', :hosts => hosts) # Stores "A bunch of text to store" into 'some_key' with a class of 'text'. mg.store_content('some_key', 'text', "A bunch of text to store") # Retrieve data from 'some_key' as a string data = mg.get_file_data('some_key') # Store the contents of 'image.jpeg' into the key 'my_image' with a # class of 'image'. mg.store_file('my_image', 'image', 'image.jpeg') # Store the contents of 'image.jpeg' into the key 'my_image' with a # class of 'image' using an open IO object. File.open('image.jpeg') { |fp| mg.store_file('my_image', 'image', fp) } # Retrieve the contents of 'my_image' into '/path/to/huge_file' # without slurping the entire contents into memory: mg.get_file_data('my_image', '/path/to/huge_file') # Remove the key 'my_image' and 'some_key'. mg.delete('my_image') mg.delete('some_key')
The domain of keys for this MogileFS
client.
The timeout for get_file_data
(per-read() system call). Defaults to five seconds.
The maximum allowed time for creating a new_file. Defaults to 1 hour.
new (args = {}) source
Creates a new MogileFS::MogileFS
instance. args
must include a key :domain specifying the domain of this client.
Optional parameters for args
:
Delay before retrying a failed tracker backends. Defaults to 5 seconds.
Timeout for tracker backend responses. Defaults to 3 seconds.
Timeout for connecting to a tracker Defaults to 3 seconds
delete (key) source
Removes key
.
each_file_info (prefix = "", args = nil) { |info| ... } source
Enumerates keys and yields a file_info
hash for each key matched by prefix
each_key (prefix = "", args = nil, &block) source
Enumerates keys, limited by optional prefix
args
may also be specified for an optional :limit
and :after
(default: nil)
exist? (key) source
Returns true
if key
exists, false
if not
file_debug (args) source
Given an Integer fid
or String key
and domain, thorougly search the database for all occurences of a particular fid.
Use this sparingly, this command hits the master database numerous times and is very expensive. This is not for production use, only troubleshooting and debugging.
Searches for fid=666:
client.file_debug(666)
Search for key=foo using the default domain for this object:
client.file_debug("foo")
Search for key=foo in domain="bar":
client.file_debug(:key => "foo", :domain => "bar")
file_info (key, args = nil) source
Return metadata about a file as a hash. Returns the domain, class, length, devcount, etc. as keys. Optionally, device ids (not paths) can be returned as well if :devices is specified and true
.
This should only be used for informational purposes, and not usually for dynamically serving files.
mg.file_info("bar")
Returns:
{ "domain" => "foo", "key" => "bar", "class" => "default", "devcount" => 2, "length => 666 }
get_file_data (key, dst = nil, copy_length = nil, src_offset = nil) { |sock| ... } source
Retrieves the contents of key
. If dst
is specified, dst
should be an IO-like object capable of receiving the write
method or a path name. copy_length
may be specified to limit the number of bytes to retrieve, and src_offset
can be specified to specified the start position of the copy.
get_paths (key, *args) source
Get the paths (URLs as strings) for key
. If args
is specified, it may contain:
:noverify -> boolean, whether or not the tracker checks (default: true)
:pathcount -> a positive integer of URLs to retrieve (default: 2)
:zone -> "alt" or nil (default: nil)
:noverify defaults to true because this client library is capable of verifying paths for readability itself. It is also faster and more reliable to verify paths on the client.
get_uris (key, *args) source
Get the URIs for key
(paths) as URI::HTTP objects
list_keys (prefix = "", after = nil, limit = 1000, &block) source
Lists keys starting with prefix
following after
up to limit
. If after
is nil the list starts at the beginning.
new_file (key, args = nil, bytes = nil) { |file| ... } source
Creates a new file key
in the domain of this object.
bytes
is the expected size of the file if known in advance
It operates like File.open(..., "w") and may take an optional block, yielding an IO-like object with support for the methods documented in MogileFS::NewFile::Writer
.
This atomically replaces existing data stored as key
when the block exits or when the returned object is closed.
args
may contain the following options:
This has the same effect as the (deprecated) bytes
parameter.
See MogileFS::NewFile
for more information on this
The MogileFS
storage class of the object.
This can either be a Base64-encoded String, a Proc object, or the :trailer symbol. If given a String, it will be used as the Content-MD5 HTTP header. If given the :trailer symbol, this library will automatically generate an Content-MD5 HTTP trailer. If given a Proc object, this Proc object should give a Base64-encoded string which can be used as the Content-MD5 HTTP trailer when called at the end of the request.
Keep in mind most HTTP servers do not support HTTP trailers, so passing a String is usually the safest way to use this.
This is an empty hash that will be filled the same information MogileFS::MogileFS#file_info
.
Additionally, it contains one additional key: :uris, an array of URI::HTTP objects to the stored destinations
rename (from, to) source
Renames a key from
to key to
.
size (key) source
Returns the size of key
.
store_content (key, klass, content, opts = nil) source
Stores content
into key
in class klass
, where content
is a String This atomically replaces existing data stored as key
store_file (key, klass, file, opts = nil) source
Copies the contents of file
into key
in class klass
. file
can be either a path name (String or Pathname object) or an IO-like object that responds to read or readpartial. Returns size of file
stored. This atomically replaces existing data stored as key
updateclass (key, newclass) source
Updates key
to newclass
Parent: MogileFS::Client
Included modules: MogileFS::Bigfile
Pages
Classes
Methods
mail archives: https://yhbt.net/mogilefs-client-public/ http://ou63pmih66umazou.onion/mogilefs-client-public/ nntp://news.public-inbox.org/inbox.comp.file-systems.mogilefs.ruby nntp://ou63pmih66umazou.onion/inbox.comp.file-systems.mogilefs.ruby public: mogilefs-client-public@yhbt.net source code: git clone https://yhbt.net/mogilefs-client.git torsocks git clone http://ou63pmih66umazou.onion/mogilefs-client.git