Comparing version 3.1.0 to 3.2.0
@@ -0,1 +1,11 @@ | ||
<a name="3.2.0"></a> | ||
# [3.2.0](https://github.com/image-js/iobuffer/compare/v3.1.0...v3.2.0) (2016-12-27) | ||
### Features | ||
* add readUtf8 and writeUtf8 ([6118a54](https://github.com/image-js/iobuffer/commit/6118a54)), closes [#31](https://github.com/image-js/iobuffer/issues/31) | ||
<a name="3.1.0"></a> | ||
@@ -2,0 +12,0 @@ # [3.1.0](https://github.com/image-js/iobuffer/compare/v3.0.0...v3.1.0) (2016-12-15) |
'use strict'; | ||
const utf8 = require('utf8'); | ||
const defaultByteLength = 1024 * 8; | ||
@@ -329,2 +331,13 @@ const charArray = []; | ||
/** | ||
* Read the next n bytes, return a UTF-8 decoded string and move pointer forward | ||
* @param {number} n | ||
* @return {string} | ||
*/ | ||
readUtf8(n) { | ||
if (n === undefined) n = 1; | ||
const bString = this.readChars(n); | ||
return utf8.decode(bString); | ||
} | ||
/** | ||
* Write 0xff if the passed value is truthy, 0x00 otherwise | ||
@@ -486,2 +499,12 @@ * @param {any} value | ||
/** | ||
* UTF-8 encode and write the passed string to the current pointer offset | ||
* @param {string} str | ||
* @return {IOBuffer} | ||
*/ | ||
writeUtf8(str) { | ||
const bString = utf8.encode(str); | ||
return this.writeChars(bString); | ||
} | ||
/** | ||
* Export a Uint8Array view of the internal buffer. | ||
@@ -488,0 +511,0 @@ * The view starts at the byte offset and its length |
{ | ||
"name": "iobuffer", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "Read and write binary data on ArrayBuffers", | ||
@@ -34,3 +34,6 @@ "main": "./IOBuffer.js", | ||
"should": "^11.1.0" | ||
}, | ||
"dependencies": { | ||
"utf8": "^2.1.2" | ||
} | ||
} |
@@ -24,3 +24,3 @@ # iobuffer | ||
io | ||
.writeChars('Hello world') // Written 11 chars, pointer offset now 11 | ||
.writeChars('Hello world') // Written 11 chars, pointer offset now 11 (->15) | ||
.writeUint32(42) // Written 32-bit int (default is little-endian), pointer offset now 15 | ||
@@ -36,5 +36,3 @@ .setBigEndian() // Switch to big-endian mode | ||
.rewind() // Pointer offset now 0 | ||
.toArray() // Create a DataView of the internal Buffer that ranges over the written buffer [0-21] | ||
.getBuffer() // Get a DataView or Buffer (in node.js) over the written part [0-21] of the internal Buffer | ||
``` | ||
@@ -41,0 +39,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21150
491
1
50
+ Addedutf8@^2.1.2
+ Addedutf8@2.1.2(transitive)