File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,7 +23,12 @@ class Document
2323 def initialize ( path_or_io , options = { } )
2424 @replace = { }
2525
26- @zip = options [ :use_buffer ] ? Zip ::File . open_buffer ( path_or_io ) : Zip ::File . open ( path_or_io )
26+ # if path-or_io is string && does not contain a null byte
27+ if ( path_or_io . instance_of? ( String ) && !/\u0000 / . match? ( path_or_io ) )
28+ @zip = Zip ::File . open ( path_or_io )
29+ else
30+ @zip = Zip ::File . open_buffer ( path_or_io )
31+ end
2732
2833 @document_xml = @zip . read ( 'word/document.xml' )
2934 @doc = Nokogiri ::XML ( @document_xml )
@@ -49,10 +54,6 @@ def self.open(path, &block)
4954 new ( path , &block )
5055 end
5156
52- def self . open_buffer ( buffer , &block )
53- new ( buffer , use_buffer : true , &block )
54- end
55-
5657 def paragraphs
5758 @doc . xpath ( '//w:document//w:body/w:p' ) . map { |p_node | parse_paragraph_from p_node }
5859 end
Original file line number Diff line number Diff line change 8686 context 'using stream' do
8787 before do
8888 stream = File . binread ( @fixtures_path + '/basic.docx' )
89- @doc = Docx ::Document . open_buffer ( stream )
89+ @doc = Docx ::Document . open ( stream )
9090 end
9191
9292 it_behaves_like 'reading'
365365 context 'from a stream' do
366366 before do
367367 stream = File . binread ( @fixtures_path + '/saving.docx' )
368- @doc = Docx ::Document . open_buffer ( stream )
368+ @doc = Docx ::Document . open ( stream )
369369 end
370370
371371 it_behaves_like 'saving to file'
393393 doc = Docx ::Document . open ( @fixtures_path + '/basic.docx' )
394394 result = doc . stream
395395
396- @doc = Docx ::Document . open_buffer ( result )
396+ @doc = Docx ::Document . open ( result )
397397 end
398398
399399 it_behaves_like 'reading'
You can’t perform that action at this time.
0 commit comments