lib/axlsx/package.rb in axlsx-2.0.0 vs lib/axlsx/package.rb in axlsx-2.0.1
- old
+ new
@@ -68,11 +68,11 @@
@workbook
end
#def self.parse(input, confirm_valid = false)
# p = Package.new
- # z = Zip::ZipFile.open(input)
+ # z = Zip::File.open(input)
# p.workbook = Workbook.parse z.get_entry(WORKBOOK_PN)
# p
#end
# @see workbook
@@ -99,11 +99,11 @@
# s = p.to_stream()
# File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) }
def serialize(output, confirm_valid=false)
return false unless !confirm_valid || self.validate.empty?
Relationship.clear_cached_instances
- Zip::ZipOutputStream.open(output) do |zip|
+ Zip::OutputStream.open(output) do |zip|
write_parts(zip)
end
true
end
@@ -112,11 +112,11 @@
# @param [Boolean] confirm_valid Validate the package prior to serialization.
# @return [StringIO|Boolean] False if confirm_valid and validation errors exist. rewound string IO if not.
def to_stream(confirm_valid=false)
return false unless !confirm_valid || self.validate.empty?
Relationship.clear_cached_instances
- zip = write_parts(Zip::ZipOutputStream.new("streamed", true))
+ zip = write_parts(Zip::OutputStream.new("streamed", true))
stream = zip.close_buffer
stream.rewind
stream
end
@@ -152,12 +152,12 @@
end
private
# Writes the package parts to a zip archive.
- # @param [Zip::ZipOutputStream] zip
- # @return [Zip::ZipOutputStream]
+ # @param [Zip::OutputStream] zip
+ # @return [Zip::OutputStream]
def write_parts(zip)
p = parts
p.each do |part|
unless part[:doc].nil?
zip.put_next_entry(zip_entry_for_part(part))
@@ -171,25 +171,25 @@
end
end
zip
end
- # Generate a ZipEntry for the given package part.
- # The important part here is to explicitly set the timestamp for the zip entry: Serializing axlsx packages
+ # Generate a Entry for the given package part.
+ # The important part here is to explicitly set the timestamp for the zip entry: Serializing axlsx packages
# with identical contents should result in identical zip files – however, the timestamp of a zip entry
# defaults to the time of serialization and therefore the zip file contents would be different every time
# the package is serialized.
#
# Note: {Core#created} also defaults to the current time – so to generate identical axlsx packages you have
# to set this explicitly, too (eg. with `Package.new(created_at: Time.local(2013, 1, 1))`).
#
# @param part A hash describing a part of this pacakge (see {#parts})
- # @return [Zip::ZipEntry]
+ # @return [Zip::Entry]
def zip_entry_for_part(part)
timestamp = Zip::DOSTime.at(@core.created.to_i)
- Zip::ZipEntry.new("", part[:entry], "", "", 0, 0, Zip::ZipEntry::DEFLATED, 0, timestamp)
+ Zip::Entry.new("", part[:entry], "", "", 0, 0, Zip::Entry::DEFLATED, 0, timestamp)
end
-
+
# The parts of a package
# @return [Array] An array of hashes that define the entry, document and schema for each part of the package.
# @private
def parts
parts = [