lib/fastdfs-client/storage.rb in fastdfs-client-1.0.0 vs lib/fastdfs-client/storage.rb in fastdfs-client-1.0.1
- old
+ new
@@ -26,11 +26,11 @@
client.push_content{ IO.read(file) }
client.dispose do |body|
group_name_max_len = ProtoCommon::GROUP_NAME_MAX_LEN
res = {group_name: body[0...group_name_max_len].strip, path: body[group_name_max_len..-1]}
- _set_metadata(res[:path], res[:group_name], options) unless options.blank?
+ _set_metadata(res[:path], res[:group_name], options) unless Utils.is_blank?(options)
res
end
end
def delete(path, group_name = nil)
@@ -84,16 +84,15 @@
path_bytes = group_path_bytes(path, group_name).flatten
return (ProtoCommon.header_bytes(cmd, path_bytes.length) + path_bytes)
end
def extract_path!(path, group_name = nil)
- raise "path arguments is empty!" if path.blank?
- if group_name.blank?
+ raise "path arguments is empty!" if Utils.is_blank? path
+ if Utils.is_blank? group_name
group_name = /^\/?(\w+)/.match(path)[1]
path = path.gsub(Regexp.new("/?#{group_name}/?"), "")
end
- raise "group_name arguments is empty!" if group_name.blank?
return group_name, path
end
def _set_metadata(path, group_name = nil, options = {}, flag = :cover)
flag = convert_meta_flag(flag)
@@ -112,18 +111,18 @@
def convert_meta_flag(flag)
data = {
cover: ProtoCommon::SET_METADATA_FLAG_OVERWRITE,
merge: ProtoCommon::SET_METADATA_FLAG_MERGE
}
- flag = :cover if flag.blank?
+ flag ||= :cover
data[flag.to_sym]
end
def meta_to_bytes(options = {})
meta_bytes = options.map do |a|
a.join(ProtoCommon::FILE_SEPERATOR)
end.join(ProtoCommon::RECORD_SEPERATOR).bytes
- meta_bytes << 0 if meta_bytes.blank?
+ meta_bytes << 0 if meta_bytes.length <= 0
meta_bytes
end
def create_tempfile(path, body)
tmp = Tempfile.new(path.gsub(/\//, "_"))
\ No newline at end of file