5414: Merge branch 'master' into 5414-keep-service-hints
[arvados.git] / sdk / ruby / lib / arvados / keep.rb
index d966727de9b8af1e8c27ef57fde3dde55f33cb3a..e4f62083b0d5568d757d8ae05dc043170e10f6ca 100644 (file)
@@ -138,11 +138,14 @@ module Keep
 
     def split_file_token token
       start_pos, filesize, filename = token.split(':', 3)
-      [start_pos.to_i, filesize.to_i, filename]
+      if filename.nil?
+        raise ArgumentError.new "Invalid file token '#{token}'"
+      end
+      [start_pos.to_i, filesize.to_i, unescape(filename)]
     end
 
     def each_file_spec
-      return to_enum(__method__, speclist) unless block_given?
+      return to_enum(__method__) unless block_given?
       @text.each_line do |line|
         stream_name = nil
         in_file_tokens = false
@@ -188,6 +191,11 @@ module Keep
       seen_files.size
     end
 
+    def files_size
+      # Return the total size of all files in this manifest.
+      files.reduce(0) { |total, (_, _, size)| total + size }
+    end
+
     def exact_file_count?(want_count)
       files_count(want_count + 1) == want_count
     end