From 443d7bdf4c1fb3b950cd05ffb475aef12d50c4b6 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 2 Nov 2011 22:33:01 +0000 Subject: bigfile: make parse_info public and require arg --- lib/mogilefs/bigfile.rb | 50 +++++++++++++++++++++++-------------------------- test/test_bigfile.rb | 2 +- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/lib/mogilefs/bigfile.rb b/lib/mogilefs/bigfile.rb index 1be36a5..1f9d0ba 100644 --- a/lib/mogilefs/bigfile.rb +++ b/lib/mogilefs/bigfile.rb @@ -12,7 +12,7 @@ module MogileFS::Bigfile # returns a big_info hash if successful def bigfile_stat(key) - parse_info(get_file_data(key)) + bigfile_parse_info(get_file_data(key)) end # returns total bytes written and the big_info hash if successful, raises an @@ -51,34 +51,30 @@ module MogileFS::Bigfile [ total, info ] end - private - - include MogileFS::Util - - ## - # parses the contents of a _big_info: string or IO object - def parse_info(info = '') - rv = { :parts => [] } - info.each_line do |line| - line.chomp! - case line - when /^(des|type|filename)\s+(.+)$/ - rv[$1.to_sym] = $2 - when /^compressed\s+([01])$/ - rv[:compressed] = ($1 == '1') - when /^(chunks|size)\s+(\d+)$/ - rv[$1.to_sym] = $2.to_i - when /^part\s+(\d+)\s+bytes=(\d+)\s+md5=(.+)\s+paths:\s+(.+)$/ - rv[:parts][$1.to_i] = { - :bytes => $2.to_i, - :md5 => $3.downcase, - :paths => $4.split(/\s*,\s*/), - } - end + ## + # parses the contents of a _big_info: string or IO object + def bigfile_parse_info(info) # :nodoc: + rv = { :parts => [] } + info.each_line do |line| + line.chomp! + case line + when /^(des|type|filename)\s+(.+)$/ + rv[$1.to_sym] = $2 + when /^compressed\s+([01])$/ + rv[:compressed] = ($1 == '1') + when /^(chunks|size)\s+(\d+)$/ + rv[$1.to_sym] = $2.to_i + when /^part\s+(\d+)\s+bytes=(\d+)\s+md5=(.+)\s+paths:\s+(.+)$/ + rv[:parts][$1.to_i] = { + :bytes => $2.to_i, + :md5 => $3.downcase, + :paths => $4.split(/\s*,\s*/), + } end - - rv end + + rv + end end require "mogilefs/bigfile/filter" diff --git a/test/test_bigfile.rb b/test/test_bigfile.rb index c99b878..8cf4624 100644 --- a/test/test_bigfile.rb +++ b/test/test_bigfile.rb @@ -41,7 +41,7 @@ size 18 part 1 bytes=12 md5=d3b4d15c294b24d9f853e26095dfe3d0 paths: http://foo1:7500/dev2/0/000/144/0000144411.fid, http://foo2:7500/dev1/0/000/144/0000144411.fid part 2 bytes=6 md5=d3b4d15c294b24d9f853e26095dfe3d0 paths: http://foo4:7500/dev2/0/000/144/0000144411.fid, http://foo3:7500/dev1/0/000/144/0000144411.fid EOS - i = parse_info(s) + i = bigfile_parse_info(s) assert_equal expect, i end -- cgit v1.2.3-24-ge0c7