I’m pretty new to Ruby, I’m taking courses and reading as much info as I
can, but I’m stuck on this one problem that may/may not have a simple
A quick summary of what I’m trying to accomplish:
I’ve written a simple SOAP client that interfaces with a web app used
for file transfer… It works great, however, if a file is over a
certain size it just hangs - and I know the reason why…
The webapp receives the file as a chunk, in the form of a byte array,
the great thing about Ruby is that strings are basically an arrangement
of arbitrary bytes, so I can just pass a string with the file object
into the web service and upload small files.
But I’d like to split a file into “chunks” … I know that I can do this:
bytearray.read(61440) #read a 60kb chunk of the byte array
localFile = File.open(‘test.dat’)
But I need to keep track of more information … The web app is looking
for an offset integer , which basically works like this:
(with a 60k chunksize)
the first request will be:
offset = 0
offset = 61440
offset = 122880
Does anyone know how I could iterate over a bytearray, keeping track of
the offset, and read 60k chunks all at the same time?
in pseudo code:
offset = 0
offset += 61440
After I have the proper offset, and chunks of a bytearray - I need to
keep calling the web service method with that data until the file = eof.
I’m horrible at code blocks and iteration, if anyone has any
suggestions, it would be greatly appreciated.