I am writing an application to transfer a network file. Using Lazy ByteString as an Intermediate
import qualified Data.ByteString.Lazy as BSL
When building BSL from a local file, put the BSL in the Handle of Socket:
BSL.readFile filename >>= BSL.hPut remoteH -- OK
It works great. Memory usage is permanent. But to get data from Socket, then write to a local file:
BSL.hGet remoteH size >>= BSL.hPut fileH bs -- starts swapping in 1 second
I see that memory usage continues to grow, BSL takes the size of bytes of memory. Worse, for a large size that exceeded my physical memory size, the OS immediately begins to replace.
I have to recursively get ByteStrings segments. This is normal.
Why does BSL behave like this?