@@ -17,38 +17,30 @@ This is just a small example of what Restructure can do. Check out the API docum
1717below for more information.
1818
1919``` javascript
20- var r = require ( ' restructure' ) ;
20+ import * as r from ' restructure' ;
2121
22- var Person = new r.Struct ({
22+ let Person = new r.Struct ({
2323 name: new r.String (r .uint8 , ' utf8' ),
2424 age: r .uint8
2525});
2626
2727// decode a person from a buffer
28- var stream = new r.DecodeStream (buffer);
29- Person .decode (stream); // returns an object with the fields defined above
28+ let value = Person .fromBuffer (new Uint8Array ([/* ... */ ])); // returns an object with the fields defined above
3029
3130// encode a person from an object
32- // pipe the stream to a destination, such as a file
33- var stream = new r.EncodeStream ();
34- stream .pipe (fs .createWriteStream (' out.bin' ));
35-
36- Person .encode (stream, {
31+ let buffer = Person .toBuffer ({
3732 name: ' Devon' ,
3833 age: 21
3934});
40-
41- stream .end ();
4235```
4336
44-
4537## API
4638
4739All of the following types support three standard methods:
4840
49- * ` decode(stream )` - decodes an instance of the type from the given DecodeStream
41+ * ` fromBuffer(buffer )` - decodes an instance of the type from the given Uint8Array
5042* ` size(value) ` - returns the amount of space the value would take if encoded
51- * ` encode(stream, value)` - encodes the given value into the given EncodeStream
43+ * ` toBuffer( value)` - encodes the given value into a Uint8Array
5244
5345Restructure supports a wide variety of types, but if you need to write your own for
5446some custom use that cannot be represented by them, you can do so by just implementing
@@ -143,7 +135,7 @@ bitfield.encode(stream, result);
143135
144136### Buffer
145137
146- Extracts a slice of the buffer to a Node ` Buffer ` . The length can be a constant, or taken from
138+ Extracts a slice of the buffer to a ` Uint8Array ` . The length can be a constant, or taken from
147139a previous field in the parent structure.
148140
149141``` javascript
@@ -162,8 +154,9 @@ var struct = new r.Struct({
162154A ` String ` maps a JavaScript string to and from binary encodings. The length can be a constant, taken
163155from a previous field in the parent structure, or encoded using a number type immediately before the string.
164156
165- Supported encodings include ` 'ascii' ` , ` 'utf8' ` , ` 'ucs2' ` , ` 'utf16le' ` , ` 'utf16be' ` , and if you also install
166- [ iconv-lite] ( https://github.com/ashtuchkin/iconv-lite ) , many other legacy codecs.
157+ Fully supported encodings include ` 'ascii' ` , ` 'utf8' ` , ` 'ucs2' ` , ` 'utf16le' ` , ` 'utf16be' ` . Decoding is also possible
158+ with any encoding supported by [ TextDecoder] ( https://developer.mozilla.org/en-US/docs/Web/API/Encoding_API/Encodings ) ,
159+ however encoding these is not supported.
167160
168161``` javascript
169162// fixed length, ascii encoding by default
0 commit comments