Mercurial > hg > may
changeset 572:aca6a6604fdc
Add read-all
author | Chris Cannam |
---|---|
date | Tue, 20 May 2014 13:36:02 +0100 |
parents | d72c054fc8bf |
children | 5474b55b3071 |
files | src/may/stream/readall.yeti |
diffstat | 1 files changed, 26 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/may/stream/readall.yeti Tue May 20 13:36:02 2014 +0100 @@ -0,0 +1,26 @@ + +module may.stream.readall; + +load may.stream.type; + +mat = load may.matrix; +af = load may.stream.audiofile; + +readAll stream = + case stream.available of + Known n: stream.read n; + _: failWith "Cannot readAll from infinite or unknown-duration stream"; + esac; + +//!!! todo: use openWith (when available!) +readAllFrom filename = + (str = af.open filename; + mat = readAll str; + str.close (); + mat); + +{ + readAll is stream_t -> mat.matrix_t, + readAllFrom is string -> mat.matrix_t, +} +