Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/doc2text/xml_based_document_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ def initialize(document_path)
def unpack
Zip::File.open(@document_path) {
|zip_file|
Dir.mkdir(extract_path)
zip_file.each do |entry|
zipped_file_extract_path = File.join extract_path, entry.name
FileUtils.mkdir_p File.dirname(zipped_file_extract_path)
zip_file.extract entry, zipped_file_extract_path
zip_file.extract entry, zipped_file_extract_path, destination_directory: "/"
Comment thread
alecslupu marked this conversation as resolved.
Outdated
end
}
end
Expand All @@ -41,7 +40,7 @@ def extract_extension
end

def extract_path
File.join File.dirname(@document_path), ".#{File.basename(@document_path)}_#{extract_extension}"
@extract_path ||= Dir.mktmpdir(".#{File.basename(@document_path)}_#{extract_extension}")
end
Comment thread
alecslupu marked this conversation as resolved.
Comment thread
alecslupu marked this conversation as resolved.
end
end
Expand Down
19 changes: 19 additions & 0 deletions spec/unpack_odt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,23 @@ def rspec_extract_odt
rspec_extract_odt
rspec_extract_odt
end

context "when the odt is a temporary file" do
it "runs from a temp file" do
tempfile = Tempfile.new('text_styles.odt')
tempfile.write File.read(File.join 'spec', 'fixtures', 'text_styles.odt')
Comment on lines +22 to +25
tempfile.rewind
Comment thread
alecslupu marked this conversation as resolved.
tempfile.close

@odt = Doc2Text::Odt::Document.new tempfile
@odt.unpack

entries = Dir.glob "#{@odt.extract_path}/**/*"
mandatory_files = %w(manifest.rdf content.xml settings.xml styles.xml META-INF META-INF/manifest.xml meta.xml mimetype).map { |entry|
File.join @odt.extract_path, entry }
expect(entries.to_set.subset? mandatory_files.to_set)

Comment thread
alecslupu marked this conversation as resolved.
@odt.clean
Comment thread
alecslupu marked this conversation as resolved.
end
end
end
Loading