Interfaces > Core Interfaces > MemStream |
The MemStream Core Interface was first introduced in gMax 1.0 and is available in MAXScript since 3ds Max 5.
It provides fast stream parsing by loading the entire file into memory.
The memStreamMgr and memStream interfaces provide a large set of methods for parsing the stream.
<Interface>MemStreamMgr.openFile <filename>fname favor_type:<enum> code_page:<integer> favor_type enums: {#FAVOR_ACP|#FAVOR_UTF8} favor_type default value: #FAVOR_ACP code_page default value: 0
Returns a memStream interface where the content of the specified file is the input stream to be processed.
If the file cannot be opened, a value of undefined is returned.
The optional keyword arguments favor_type: and code_page: available in 3ds Max 2013 and higher provide control over the stream Encoding.
UTF8 stands for UCS Transformation Format - 8 bit, where UCS stands for Universal Character Set.
Returns a memStream interface where the content of the string is the input stream to be processed.
Closes the input stream for the memStream, freeing the memory associated with this stream.
The memStream Interface provides methods for parsing the input stream. This interface is returned from the memStreamMgr.openString() and memStreamMgr.openFile() methods.
Returns the file name that the memStream was created from. Returns "" if the interface was created using memStreamMgr.openString().
Skips leading whitespace characters (space, tab, and newlines) starting at the current stream cursor position. Following this call the stream cursor position will be at a non-whitespace character, or at the end of the stream.
Reads a single character from the stream, returning it as a string.
Reads a single character from the stream, returning it as a string. Does not increment the stream cursor position.
Reads all characters from the current stream cursor position until a newline and returns it as a string.
Reads a token from the given stream and returns it as a string. A token is defined by a sequence of characters surrounded by whitespace or the stream start or end. Leading whitespace and one line "//" style comments are automatically skipped.
The maximum allowed length of the returned string is 5120 characters. If a token larger than this length is read, the string returned contains the first 5120 characters of the token. The stream cursor position will be at the next character.
Same as <memStream>.readToken except it does not increment the stream cursor position.
Resets the stream cursor position to right before the last readToken operation.
Reads a block of tokens from the 'open' token until the 'close' token, automatically skipping nested open/close token pairs, and returns the contents as a string. This string will contain the initial 'open' token and the final 'close' token. The initial 'open' token must be the next token in the input stream. If it is not, a value of ’r;undefined’ will be returned.
Following this call, the stream cursor position will be at the beginning of the next token, or at the end of the stream if there are no more tokens following the 'close' token. The comparison of tokens against the 'open' and 'close' tokens is case-insensitive.
EXAMPLE |
will return undefined, because the '{' and '}' are not surrounded by whitespace, and so are not found as tokens (the entire content of the memStream is a single token). |
If the 'open' token is not the next token in the input stream, a value of 'undefined' will be returned and the stream cursor position will be unchanged.
If the 'open' token is the next token in the input stream, but the 'close' token is not found, returns a string starting at the open token and ending at the end of stream -1 character.
The maximum allowed length of the block is 5120 characters. If a block is found, but is larger than this length, a value of 'undefined' is returned. However, the stream cursor position will be at the end of the block.
Same as readBlock except does not return the block of tokens (this is a little faster).
Returns the current stream cursor position.
<void><Interface:MemStream>.seek <integer>offset <enum>origin origin enums: {#seek_set|#seek_cur|#seek_end}
Moves the stream cursor position 'offset' number of characters from the base specified.
#seek_set-- start of file #seek_cur-- current file position #seek_end-- end of file (works with negative offset values)
Returns the size of the input stream.
Returns true if the current stream cursor position is at or past the end of the input stream, false otherwise.
The read or peek methods currently do not protect against reading past the end of the input stream.
The seek method currently does not protect against setting position past end of the input stream.
The readBlock and skipBlock methods performs case-insensitive comparisons on the open and close token strings.