lib/fog/aliyun/models/storage/files.rb in fog-aliyun-0.2.1 vs lib/fog/aliyun/models/storage/files.rb in fog-aliyun-0.2.2

- old
+ new

@@ -64,11 +64,23 @@ object = if directory.key == '' key else directory.key + '/' + key end + begin + data = service.get_object(object) + rescue => error + case error.response.body + when /<Code>NoSuchKey<\/Code>/ + nil + else + raise(error) + end + end + contentLen = data[:headers]['Content-Length'].to_i + if block_given? pagesNum = (contentLen + Excon::CHUNK_SIZE - 1) / Excon::CHUNK_SIZE for i in 1..pagesNum _start = (i - 1) * Excon::CHUNK_SIZE @@ -78,15 +90,12 @@ chunk = data[:body] yield(chunk) body = nil end else - data = service.get_object(object) body = data[:body] end - contentLen = data[:headers]['Content-Length'].to_i - return nil if data[:status] != 200 lastModified = data[:headers]['Last-Modified'] last_modified = if !lastModified.nil? && lastModified != '' Time.parse(lastModified).localtime end