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

Scanning a Tempfile which exists in memory #26

Closed
aidandamerell opened this issue Dec 10, 2018 · 2 comments
Closed

Scanning a Tempfile which exists in memory #26

aidandamerell opened this issue Dec 10, 2018 · 2 comments

Comments

@aidandamerell
Copy link

It would be handy if you could scan a Tempfile (child of File) object as it exists in memory.
irb> require 'tempfile'
file = Tempfile.open("/path/to/file/file.txt")
file.unlink
Clamby.safe?(file)

I realise this may be a limitation as clamscan but thought I would make the suggestion anyway.

@janko
Copy link

janko commented Dec 12, 2018

It appears that clamscan supports taking data from standard input, so with Open3 this should work:

require "open3"

stdout, stderr, status = Open3.popen3("clamscan -") do |stdin, stdout, stderr, thread|
  IO.copy_stream(file, stdin)
  stdin.close

  [stdout.read, stderr.read, thread.value]
end

@aidandamerell
Copy link
Author

After a bit of digging around into clamscan, it appears that there is no way to force it to solely read a file from memory. If passing input from STDIN, clamscan will write the input to a temporary file then scan that. The use-case for this request was to avoid files touching disk so it may be a little redundant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants