> As I mentioned in my previous reply and similar to the problem you had when
> creating the file: you're trying to load the whole thing.
>
> There are two options for this:
>
> A) You stream the contents of your CSV file, reading by chunks into a
> ZipStream
>

 That's exactly what I would like to do, I wasn't sure offhand if the
zip method will read it that way or how to pass it. I was hoping for
an idea on how to do that.

 The code where it all happens is here and the second line is where it
crashes:

 zos.put_next_entry(File.basename(fpath))
 zos.print IO.read(fpath)

zos is an instance of Zip::ZipOutputStream.
The print method is inherited from IOExtras::AbstractOutputStream

According to the docs, print() is like this
    def print(*params)
      self << params.to_s << $\.to_s
    end

Since it does params.to_s, I'm guessing that is going to put it all
into memory.
The other methods may have similar problems.

 However, the putc method looked interesting.

 There is a putc() defined like this according to the docs:

 def putc(anObject)
      self << case anObject
              when Fixnum then anObject.chr
              when String then anObject
              else raise TypeError, "putc: Only Fixnum and String
supported"
              end
      anObject
    end


So I tried that, here is my code, and the output follows, but the file
I was trying to zip was another zip file. It appeared to be a bit
bigger than it should have been and when I tried to open it, I got an
error saying it was corrupted.

 This isn't quite the same CSV problem, but I am doing a zip file into
a zip file here.


  def zput(zos,fpath)
    p fpath
    zos.put_next_entry(File.basename(fpath))
    f = File.new(fpath)
    chunk_sz = 10000000
    while !f.eof?
      data = f.read(chunk_sz)
      zos.putc data
      puts 'read ' + data.size.to_s + ' bytes'
    end
  end


"web.war"
read 10000000 bytes
read 10000000 bytes
read 8573823 bytes
"data.war"
read 10000000 bytes
read 8655347 bytes
"big.zip"
read 10000000 bytes
read 10000000 bytes
read 10000000 bytes
read 10000000 bytes
read 10000000 bytes
read 10000000 bytes
read 10000000 bytes
read 10000000 bytes
read 10000000 bytes
read 10000000 bytes
read 10000000 bytes
read 10000000 bytes
read 10000000 bytes
read 10000000 bytes
read 10000000 bytes
read 10000000 bytes
read 10000000 bytes
read 3431079 bytes

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to