Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary hocr file is deleted after the file is processed. #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Changes
## v3.1.3

#### Added

* Temporary hocr file is deleted after the file is processed.

## v3.1.2

#### Added
Expand Down
9 changes: 9 additions & 0 deletions lib/rtesseract/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,14 @@ module Base
def temp_file_path
Pathname.new(Dir.tmpdir).join("rtesseract_#{SecureRandom.uuid}").to_s
end

def remove_tmp_file(output_path)
Dir["#{Dir.tmpdir}/*"].each do |filename|
if filename.include?(output_path)
File.delete(filename)
break
end
end
end
end
end
5 changes: 4 additions & 1 deletion lib/rtesseract/box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ def run(source, errors, options)
options.tessedit_create_hocr = 1

RTesseract::Command.new(source, temp_file_path, errors, options).run do |output_path|
parse(File.read("#{output_path}.hocr"))
filename = "#{output_path}.hocr"
content = File.read(filename)
remove_tmp_file(filename)
parse(content)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rtesseract/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class RTesseract
VERSION = '3.1.2'
VERSION = '3.1.3'
end
6 changes: 6 additions & 0 deletions spec/rtesseract/box_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@
it 'bounding box' do
expect(instance.to_box).to include(word: 'you', x_start: 69, y_start: 17, x_end: 100, y_end: 31, confidence: 96)
end

it 'removes the temp hocr file' do
initial_count = Dir["#{Dir.tmpdir}/*"].length
instance.to_box
expect(initial_count).to eql(Dir["#{Dir.tmpdir}/*"].length)
end
end