ruby-on-railsrubyrails-activejobrubyzip

rubyzip extracts empty file in activejob


I have a function in my activejob that extracts a specific file from a zip file. Following code extracted empty file.

def extract_file(from, name)
  to = get_local_dest(name)

  Zip::File.open(from) do |zip_file|
    entry = zip_file.glob(name).first
    puts entry.get_input_stream.read
    entry.extract(to)
  end

return to

end

I added a debugger and ran following line of code in console then the extracted file was not empty.

entry.extract(to)

Can anyone help me with this issue? Why this function is extract empty file when it runs in activejob?


Solution

  • your code seems to be fine. Please make sure your file is not saving again in code that proceeds.

    There are chances that it extracted fine but later in code it was save again in empty form. This had happened to me in past :)

    Let me know if this resolved your issue. :)