Repository: amzn/ion-js
Pull request #672 (2021-01-27 17:36:01)

Create  uInt8ArrayValue method for reader and deprecate Reader.byteValue
*Issue #559*

*Description of changes:*
This Pr works on the above mentioned issue for deprecating use of `Reader.byteValue()` and instead use a new method `Reader.uInt8ArrayValue()`.

*Tasks:*
- create a new method called `uInt8ArrayValue.
- deprecate use of `byteValue` from tests


Patch:
diff --git a/src/IonBinaryReader.ts b/src/IonBinaryReader.ts
index ba8708c..b8937d3 100644
--- a/src/IonBinaryReader.ts
+++ b/src/IonBinaryReader.ts
@@ -183,7 +183,11 @@ export class BinaryReader implements Reader {
   }
 
   byteValue(): Uint8Array | null {
-    return this._parser.byteValue();
+    return this._parser.uInt8ArrayValue();
+  }
+
+  uInt8ArrayValue(): Uint8Array | null {
+    return this._parser.uInt8ArrayValue();
   }
 
   booleanValue(): boolean | null {
diff --git a/src/IonParserBinaryRaw.ts b/src/IonParserBinaryRaw.ts
index 2a30f45..2fd37df 100644
--- a/src/IonParserBinaryRaw.ts
+++ b/src/IonParserBinaryRaw.ts
@@ -43,7 +43,7 @@
 //    stringValue
 //    decimalValue
 //    timestampValue
-//    byteValue
+//    uInt8ArrayValue
 
 import JSBI from "jsbi";
 import * as IonBinary from "./IonBinary";
@@ -416,6 +416,10 @@ export class ParserBinaryRaw {
   }
 
   byteValue(): Uint8Array | null {
+    return this.uInt8ArrayValue();
+  }
+
+  uInt8ArrayValue(): Uint8Array | null {
     switch (this._raw_type) {
       case IonBinary.TB_NULL:
         return null;
diff --git a/src/IonReader.ts b/src/IonReader.ts
index 2ac8b1a..7080aca 100644
--- a/src/IonReader.ts
+++ b/src/IonReader.ts
@@ -133,9 +133,20 @@ export interface Reader {
    * @return `null` if the current Ion value [[isNull]].
    *
    * @throw Error when the reader is not positioned on a `clob` or `blob` typed value.
+   * @deprecated since version 4.2. Use the `uInt8ArrayValue` method instead.
    */
   byteValue(): Uint8Array | null;
 
+  /**
+   * Returns the current value as a `Uint8Array`.  This is only valid if `type() == IonTypes.CLOB`
+   * or `type() == IonTypes.BLOB`.
+   *
+   * @return `null` if the current Ion value [[isNull]].
+   *
+   * @throw Error when the reader is not positioned on a `clob` or `blob` typed value.
+   */
+  uInt8ArrayValue(): Uint8Array | null;
+
   /**
    * Returns the current value as a [[Decimal]].  This is only valid if `type() == IonTypes.DECIMAL`.
    *
diff --git a/src/IonTextReader.ts b/src/IonTextReader.ts
index 88e0a37..6cb4aa1 100644
--- a/src/IonTextReader.ts
+++ b/src/IonTextReader.ts
@@ -300,6 +300,10 @@ export class TextReader implements Reader {
   }
 
   byteValue(): Uint8Array | null {
+    return this.uInt8ArrayValue();
+  }
+
+  uInt8ArrayValue(): Uint8Array | null {
     this.load_raw();
     switch (this._type) {
       case IonTypes.NULL:


Test patch:
diff --git a/test/IonTextReader.ts b/test/IonTextReader.ts
index d037715..9fa9986 100644
--- a/test/IonTextReader.ts
+++ b/test/IonTextReader.ts
@@ -68,7 +68,7 @@ class IonTextReaderTests {
         let ionReader = ion.makeReader(ionToRead);
         ionReader.next();
 
-        assert.deepEqual(ionReader.byteValue(), Uint8Array.from([194, 128]));
+        assert.deepEqual(ionReader.uInt8ArrayValue(), Uint8Array.from([194, 128]));
     }
 
     @test "Read boolean value in struct"() {
diff --git a/test/iontests.ts b/test/iontests.ts
index 79f15f4..928763f 100644
--- a/test/iontests.ts
+++ b/test/iontests.ts
@@ -295,7 +295,7 @@ function roundTripEventStreams(input: string | Buffer) {
 //       (e.g., a class that implements IonReader)
 let allValueMethods = [
   "booleanValue",
-  "byteValue",
+  "uInt8ArrayValue",
   "decimalValue",
   "numberValue",
   "stringValue",
@@ -304,7 +304,7 @@ let allValueMethods = [
 let nonThrowingMethods = {
   null: {
     booleanValue: 1,
-    byteValue: 1,
+    uInt8ArrayValue: 1,
     decimalValue: 1,
     numberValue: 1,
     stringValue: 1,
@@ -317,8 +317,8 @@ let nonThrowingMethods = {
   timestamp: { timestampValue: 1 },
   symbol: { stringValue: 1 },
   string: { stringValue: 1 },
-  clob: { byteValue: 1 },
-  blob: { byteValue: 1 },
+  clob: { uInt8ArrayValue: 1 },
+  blob: { uInt8ArrayValue: 1 },
   list: {},
   sexp: {},
   struct: {},