I/O from binaries

Bengt Kleberg eleberg@REDACTED
Mon Nov 5 08:17:24 CET 2001



> Subject: I/o frmo binaries
> MIME-Version: 1.0
> Content-ID: <1360.1004902273.0@REDACTED>
> Date: Sun, 04 Nov 2001 20:32:08 +0100
> From: Robert Virding <rv@REDACTED>
> 
> Many have requested a module which allows doing i/o to/from binaries.
> Here is a small module I have fixed which does this.  It only
> preliminary but seems to work ok.
> 
> The API is:
> 
> bin_io:open_read(Binary) -> {ok,IoStream}
> bin_io:open_create() -> {ok,IoStream}
> bin_io:open_append(Binary) -> {ok,IoStream}

Any reasons to avoid:

bin_io:open( Binary, [read] )

etc?

> bin_io:close(IoStream) -> ok | {ok,Binary}
> 
> If the binary was opened for write or append then bin_io:close will
> return the resultant binary, otherwise just ok.

Are there any possibilities of errors? (Not only for close(), but all of them)

> In this version you can only read *or* write to a binary IoStream
> depending on how it was opened.  Would it be interesting to be able to
> do the file operations like positioning, reading and writing, etc?

Yes.

> As an extra bonus I include a modified epp which can read from an
> already opened IoStream, like a bin_io.  To use is you do:
...deleted
> N.B. Epp does not close the IoStream as it did not open it.

Good design.


bengt




More information about the erlang-questions mailing list