archivo zip de importación ftp con datos csv, obteniendo "cadena contiene byte nulo"

Estoy importando archivos zipa través de ftp Me gusta esto

files = []
Net::FTP.open(SERVER_DOMAIN) do |ftp|
  ftp.passive = true
  ftp.login(FTP_USERNAME, FTP_PASSWORD)
  day_range = (Time.now - DAY_RANGE.hours)..Time.now
  file_names = ftp.nlst
  file_names.each do |file_name|
    if day_range.cover?(ftp.mtime(file_name))
      file = ftp.getbinaryfile(file_name,nil, blocksize=1024)
      files << file
    end
  end
end
files

y luego paso cada archivo a este bloque.

def unzip file
# I've tried putting `file`, which is really just content, into a `Tempfile`
# and passing that into `Zip::ZipFile.open` but I get an error then too
  data = ""
  Zip::ZipFile.open(file) do |zipfile|
    debugger
    zipfile.each do |entry|
      data = entry.file.read(entry.name)
    end
  end
end

Antes de llegar al depurador recibo este error

ArgumentError: string contains null byte

el final de la cola de los contenidos defile se parece a esto

?*\xA2\xCD`\x12\xB6\x93\x94\xDE\xF0\xA1\x93E8\xF3o\x11\x02\xF6\xD9.%}\x19\xC7I)\xD9\x0F*\x14\xAB\xC4\x8C\x8A[\xF1\xA5\x98\x19N2qd\x9D\x89\xFD\xA0\x81N\\\x88>E\xF3$X\x1DTBbV<\xF9\xB7\xB5V\xCE9\xEB\x84<\xEB\"\xA4\xCA\x15\xFE\x7F\x01PK\a\b\x15\xAEX\x99\xEA\xF0\x02\x00\xF4\xD9)\x00PK\x01\x02\x14\x00\x14\x00\b\b\b\x00\x97F<D\x15\xAEX\x99\xEA\xF0\x02\x00\xF4\xD9)\x00\e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00KS_Google_Bing-20140128.csvPK\x05\x06\x00\x00\x00\x00\x01\x00\x01\x00I\x00\x00\x003\xF1\x02\x00\x00\x00"
Sin embargo, ¡funciona desde un zip local!

Si paso el mismo archivo zip de mi directorio público, todo funciona bien.

def unzip file
  data = ""
  Zip::ZipFile.open("public/my.zip") do |zipfile| # notice I'm using a local file here instead of the passed in ftp file
    zipfile.each do |entry|
      data = entry.file.read(entry.name)
    end
  end
end

Y si miro el contenido del archivo localpublic/my.zip con un código como este:

local_file = File.open("public/my.zip")

el final de la colalocal_file.read Se ve como esto.

FB\xC9ã\u000F\xE1\xEDB*\x8A\xDBT\x94\u0004\xAC;\u05CE\xB7(?*\xA2\xCD`\u0012\xB6\x93\x94\xDE\xF0\xA1\x93E8\xF3o\u0011\u0002\xF6\xD9.%}\u0019\xC7I)\xD9\u000F*\u0014\xABČ\x8A[\xF1\xA5\x98\u0019N2qd\x9D\x89\xFD\xA0\x81N\\\x88>E\xF3$X\u001DTBbV<\xF9\xB7\xB5V\xCE9\xEB\x84<\xEB\"\xA4\xCA\u0015\xFE\u007F\u0001PK\a\b\u0015\xAEX\x99\xEA\xF0\u0002\u0000\xF4\xD9)\u0000PK\u0001\u0002\u0014\u0000\u0014\u0000\b\b\b\u0000\x97F<D\u0015\xAEX\x99\xEA\xF0\u0002\u0000\xF4\xD9)\u0000\e\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000KS_Google_Bing-20140128.csvPK\u0005\u0006\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000I\u0000\u0000\u00003\xF1\u0002\u0000\u0000\u0000"

Entonces, ninguno de los dos se parece al binario sin formato del archivo zip, que se ve así en el extremo posterior:

38f3 6f11 02f6 d92e 257d 19c7 4929 d90f 2a14 abc4 8c8a 5bf1 a598 194e 3271 649d 89fd a081 4e5c 883e 45f3 2458 1d54 4262 563c f9b7 b556 ce39 eb84 3ceb 22a4 ca15 fe7f 0150 4b07 0815 ae58 99ea f002 00f4 d929 0050 4b01 0214 0014 0008 0808 0097 463c 4415 ae58 99ea f002 00f4 d929 001b 0000 0000 0000 0000 0000 0000 0000 0000 004b 535f 476f 6f67 6c65 5f42 696e 672d 3230 3134 3031 3238 2e63 7376 504b 0506 0000 0000 0100 0100 4900 0000 33f1 0200 0000 

¡¡Cualquier ayuda sería increíble!!

Respuestas a la pregunta(1)

Su respuesta a la pregunta