The reason you're running out of memory is that you read the entire file into memory before processing it. Since you can only send chunks of data over the wire anyway, you should also only read one chunk at a time (that's what streams are for). So instead of this:
myStream :=
(FileStream oldFileNamed: 'big_buck_bunny_480p_surround-fix.avi').
bytes := myStream next: myStream size.
myStream close.
you should use something like this:
blockSize := 128.
myStream :=
(FileStream oldFileNamed: 'big_buck_bunny_480p_surround-fix.avi') .
[ myStream atEnd ] whileFalse: [
bytes := myStream next: blockSize.
"process your bytes here" ].
myStream close.
Or even better: use the convenience block to automatically close the stream:
blockSize := 128.
FileStream
oldFileNamed: 'big_buck_bunny_480p_surround-fix.avi'
do: [ :stream |
[ stream atEnd ] whileFalse: [
bytes := stream next: blockSize.
"process your bytes here" ].
Edit
To answer the question from your comment: if you look at FileStream>>next:
you will see the following lines:
...
[self atEnd ifTrue:
[(howManyRead + 1) to: anInteger do: [:i | newCollection at: i put: (self next)].
^newCollection].
...
This means that if you ask for more than is available, you will simply get the rest of the stream up to its end.