{- |
Functions for reading and writing data
using the endianess of the machine.
This is the way Sox handles raw data.
This module is more or less provided for completeness,
since it is based on lists,
which means that it is too slow
to process real world data.
For serious applications use Data.StorableVector.Lazy.
-}moduleSound.Sox.Signal.List(writeFile,put,withReadFile,getContents,ReadException,IOReadException,)whereimportqualifiedControl.Monad.Exception.SynchronousasSyncimportqualifiedControl.Monad.Exception.AsynchronousasAsyncimportControl.Monad.Trans.Class(lift,)importForeign.Storable(Storable(..),)importForeign(Ptr,alloca,)importSystem.IO(withBinaryFile,IOMode(WriteMode,ReadMode),Handle,hPutBuf,hGetBuf,)importControl.Exception.Extensible(SomeException,try,)importControl.Monad(liftM)importSystem.IO.Unsafe(unsafeInterleaveIO,)importPreludehiding(writeFile,readFile,getContents,)writeFile::Storablea=>FilePath->[a]->IO()writeFilefileNamesignal=withBinaryFilefileNameWriteMode(flipputsignal)put::Storablea=>Handle->[a]->IO()puthsignal=alloca$\p->mapM_(putFramehp)signalputFrame::Storablea=>Handle->Ptra->a->IO()putFramehpn=pokepn>>hPutBufhp(sizeOfn)dataReadException=BrokenFramederiving(Show,Eq,Enum)typeIOReadException=EitherReadExceptionSomeExceptionwithReadFile::Storablea=>FilePath->(Async.ExceptionalIOReadException[a]->IOb)->IObwithReadFilefileNameact=withBinaryFilefileNameReadMode$\sig->getContentssig>>=actgetContents::Storablea=>Handle->IO(Async.ExceptionalIOReadException[a])getContentsh=alloca$\p->-- Async.eatNothingT $liftM(\(Async.Exceptional(Juste)a)->Async.Exceptionalea)$Async.manySynchronousTunsafeInterleaveIO(:)[](getFramehp)getFrame::Storablea=>Handle->Ptra->Sync.ExceptionalT(MaybeIOReadException)IOagetFramehp=doletgetSize::Storablea=>a->Ptra->IntgetSizedummy_=sizeOfdummysize=getSizeundefinedpcnt<-Sync.mapExceptionT(Just.Right)$Sync.fromEitherT$try$hGetBufhpsizeSync.assertTNothing(cnt>0)Sync.assertT(Just$LeftBrokenFrame)(cnt==size)lift$peekp