janfri / mini_exiftool

This library is a wrapper for the Exiftool command-line application (https://exiftool.org) written by Phil Harvey. It provides the full power of Exiftool to Ruby: reading and writing of EXIF-data, IPTC-data and XMP-data. Branch master is for actual development and branch compatibility-version is for compatibility with Ruby 1.8 and exiftool versions prior 7.65.
GNU Lesser General Public License v2.1
213 stars 52 forks source link

Allow passing an IO to MiniExiftool.new #25

Closed Gaelan closed 8 years ago

Gaelan commented 8 years ago

This should be pretty simple to implement (just pipe the IO into exiftool -). Support for the -fast option (see #15) could be a possible improvement, but isn't necessary.

janfri commented 8 years ago

How about a pull request, if it's so simple to implement? ;-)

Gaelan commented 8 years ago

I'll try to get one done tonight. No promises.

janfri commented 8 years ago

It seems to need a little more to do, especially to handle the case to have no filename. I have already adapted the master to use Open3 instead of direct calls via backticks, so it is easier to support IOs. I will have a look at it in the next week.

janfri commented 8 years ago

I have implemented support for reading from IOs now and by the way the -fast option. Please checkout release 2.6.0.

janfri commented 8 years ago

@Gaelan Could you give me an example of your use case? Maybe one we can add to the examples of mini_exiftool?

Gaelan commented 8 years ago

@janfri I was thinking of Exiftooling a file that was already saved to S3. Another simple use case would be getting metadata from a URL.

janfri commented 8 years ago

@Gaelan How do you get a non-blocking IO-object? If I use open-uri for example the whole file will be downloaded before I can read from the IO, so the fast option doesn't make any sense here. :-(

Gaelan commented 8 years ago

@janfri I found this:

uri = URI('http://example.com/large_file')

Net::HTTP.start(uri.host, uri.port) do |http|
  request = Net::HTTP::Get.new uri

  http.request request do |response|
    open 'large_file', 'w' do |io|
      response.read_body do |chunk|
        io.write chunk
      end
    end
  end
end

It's "a bit" more verbose than open-uri, but perhaps you could adapt this to run on a separate thread and write into an IO which you then passed to EXIFtool. Surely there's a better way, right? I'll keep looking.

EDIT: also, you could just pipe out of curl.

janfri commented 8 years ago

@Gaelan Thanks a lot. I've added both to the new example show_speedup_with_fast_option. Checkout version 2.7.0.

Gaelan commented 8 years ago

@janfri Thanks for implementing this so quickly! I'll add it to my app soon.