40
edits
No edit summary |
(→Buffer) |
||
Line 142: | Line 142: | ||
=== Buffer === | === Buffer === | ||
Buffer is | Buffer is accompanied by three classes; Buffer, StringBuffer, and BlobBuffer. Buffer itself is the generic class, making calls to it will normally create either a StringBuffer or a BlobBuffer. Both StringBuffer and BlobBuffer should inherit from Buffer and return true in a <code>buf instanceof Buffer</code>. | ||
( | Buffers may implement smart resizing in the background (ie: padding arrays or whatnot to sizes to avoid reallocating on each insert) but information on this is not available to the JavaScript API. | ||
Buffers will only take their own data type as arguments. If you try to insert a String into a BlobBuffer or a Blob into a StringBuffer a TypeError will be thrown. | |||
;new Buffer(); | ;new Buffer(); | ||
: | :No-op... This simply creates an instanceof of Buffer. On it's own the Buffer class does nothing so this simply exists so that prototypes may be made that inherit from Buffer. | ||
;new | ;new StringBuffer(); | ||
: | :Creates a new empty text buffer. | ||
: | ;new BlobBuffer(); | ||
: | :Creates a new empty binary buffer. | ||
;new Buffer( | ;new StringBuffer(len); | ||
: | :Creates a new text buffer of <code>len</code> size. | ||
;new BlobBuffer(len); | |||
:Creates a new binary buffer of <code>len</code> size. | |||
;new Buffer('''String'''); | |||
:Creates a new empty StringBuffer. | |||
;new Buffer('''Blob'''); | |||
:Creates a new empty BlobBuffer. | |||
;new Buffer('''String''', len); | |||
:Creates a new StringBuffer of <code>len</code> size. | |||
;new Buffer('''Blob''', len); | |||
:Creates a new BlobBuffer of <code>len</code> size. | |||
;new Buffer(string); | |||
:Creates a new StringBuffer with the same size and contents as the string. | |||
;new Buffer(blob); | |||
:Creates a new BlobBuffer with the same size and contents as the blob. | |||
;buf.length; | ;buf.length; | ||
Line 165: | Line 177: | ||
;buf.text; | ;buf.text; | ||
:(May be removed in favor of a better idiom) | |||
:Get | :Get the type of the buffer. Binary buffers return false, text buffers return true. | ||
;buf[index]; | ;buf[index]; | ||
Line 210: | Line 221: | ||
;buf.valueOf(); | ;buf.valueOf(); | ||
:Return the non-mutable sequence for the buffer. | :Return the non-mutable sequence for the buffer. | ||
:* In | :* In a BlobBuffer this returns a Blob which matches the contents of the buffer. | ||
:* In | :* In a StringBuffer this returns a String which matches the contents of the buffer. | ||
=== String extensions === | === String extensions === |
edits