# In-memory fake File

The unit at [fs/memfile.fs] provides a memfile structure that extends files
[doc/fs/core] and provides read/write capability to a memory area. When it
reaches the end of its buffer, reads will yield EOF and writes will fail.

memfile implements all file methods, including "resize". However, this
implementation is meant to allow "truncate" to work and isn't meant to allow
buffer enlargement. In other words, use "resize" responsibly or else you'll
corrupt your memory.

On a memfile, "flush" and "close" are noops.

TODO: keep track of original size and abort with error on a resize that goes
over it.

## API

### Fields

bufptr  Pointer to the memory where this buffer lives at

### Words

newmemfile ( a u -- memfile )
  Allocate a new memfile pointing to address range "a u".

newmemfilebuf ( sz -- memfile )
  Allocate a new buffer of "sz" bytes and then call newmemfile with it.

range ( memfile -- a u )
  Return the range represented by the whole buffer.

writtenrange ( memfile -- a u )
  Yields range of buffer up until current position.

eof? ( memfile -- f )
  Whether ptr = )buf.

rewind ( memfile -- )
  Set "pos" to 0.
