Eduardo Cavazos wrote:
> It would be unwise for malloc-file-contents to operate under the assumption 
> that the 'encoding' is binary. This is one way to do it:
>
>       : malloc-file-contents ( path -- alien )
>           [
>           binary encoding set
>           file-contents >byte-array malloc-byte-array
>         ] with-scope ;
>
> I'm not satisfied with that. There should be a better way that's as concise 
> as 
> the original.
>   
Remove the >byte-array; file-contents returns a byte array with binary 
encoding (one of the benefits of having a binary encoding is that we can 
use byte arrays instead of strings when doing binary I/O). So now you have

: malloc-file-contents ( path -- alien )
    binary file-contents malloc-byte-array ;

Just as concise as the original.

> How does binary-file work?
>
>       : binary-file ( string -- path ) ... ;
>
> It takes a string and returns a path object with the encoding slot set 
> appropriately.
>
>       Path objects are the right thing
>
> Words which operate on filenames should accept strings, or the more endowed 
> path objects.
Interesting idea, but I don't see how it addresses the issue of there 
being no good default encoding.

Slava

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to