JEDI-SDL already has a unit sdlstreams.pas which has all these functions written for you, there is no need to write you own!