Skip to content

Commit

Permalink
fix: Use Uint8Array.forEach in base64FromBytes (#544)
Browse files Browse the repository at this point in the history
* Use Uint8Array.forEach in base64FromBytes

Otherwise, TypeScript 4.6.2 complains:

TS2569: Type 'Uint8Array' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.
    184 | function base64FromBytes(arr: Uint8Array): string {
    185 |   const bin: string[] = [];
  > 186 |   for (const byte of arr) {
        |                      ^^^

* Update integration test generated code.
  • Loading branch information
douglasc-nflx authored Apr 8, 2022
1 parent 8a7f11b commit c7641ce
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions integration/bytes-as-base64/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ const btoa: (bin: string) => string =
globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr: Uint8Array): string {
const bin: string[] = [];
for (const byte of arr) {
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
}
});
return btoa(bin.join(''));
}

Expand Down
4 changes: 2 additions & 2 deletions integration/bytes-node/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,9 @@ const btoa: (bin: string) => string =
globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr: Uint8Array): string {
const bin: string[] = [];
for (const byte of arr) {
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
}
});
return btoa(bin.join(''));
}

Expand Down
4 changes: 2 additions & 2 deletions integration/bytes-node/point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ const btoa: (bin: string) => string =
globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr: Uint8Array): string {
const bin: string[] = [];
for (const byte of arr) {
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
}
});
return btoa(bin.join(''));
}

Expand Down
4 changes: 2 additions & 2 deletions integration/grpc-js/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,9 @@ const btoa: (bin: string) => string =
globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr: Uint8Array): string {
const bin: string[] = [];
for (const byte of arr) {
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
}
});
return btoa(bin.join(''));
}

Expand Down
4 changes: 2 additions & 2 deletions integration/oneof-properties/oneof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ const btoa: (bin: string) => string =
globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr: Uint8Array): string {
const bin: string[] = [];
for (const byte of arr) {
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
}
});
return btoa(bin.join(''));
}

Expand Down
4 changes: 2 additions & 2 deletions integration/oneof-unions/oneof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ const btoa: (bin: string) => string =
globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr: Uint8Array): string {
const bin: string[] = [];
for (const byte of arr) {
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
}
});
return btoa(bin.join(''));
}

Expand Down
4 changes: 2 additions & 2 deletions integration/simple-long-string/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,9 @@ const btoa: (bin: string) => string =
globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr: Uint8Array): string {
const bin: string[] = [];
for (const byte of arr) {
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
}
});
return btoa(bin.join(''));
}

Expand Down
4 changes: 2 additions & 2 deletions integration/simple-long/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,9 @@ const btoa: (bin: string) => string =
globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr: Uint8Array): string {
const bin: string[] = [];
for (const byte of arr) {
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
}
});
return btoa(bin.join(''));
}

Expand Down
4 changes: 2 additions & 2 deletions integration/simple-optionals/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,9 @@ const btoa: (bin: string) => string =
globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr: Uint8Array): string {
const bin: string[] = [];
for (const byte of arr) {
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
}
});
return btoa(bin.join(''));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,9 @@ const btoa: (bin: string) => string =
globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr: Uint8Array): string {
const bin: string[] = [];
for (const byte of arr) {
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
}
});
return btoa(bin.join(''));
}

Expand Down
4 changes: 2 additions & 2 deletions integration/simple-prototype-defaults/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2369,9 +2369,9 @@ const btoa: (bin: string) => string =
globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr: Uint8Array): string {
const bin: string[] = [];
for (const byte of arr) {
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
}
});
return btoa(bin.join(''));
}

Expand Down
4 changes: 2 additions & 2 deletions integration/simple-snake/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,9 @@ const btoa: (bin: string) => string =
globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr: Uint8Array): string {
const bin: string[] = [];
for (const byte of arr) {
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
}
});
return btoa(bin.join(''));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,9 @@ const btoa: (bin: string) => string =
globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr: Uint8Array): string {
const bin: string[] = [];
for (const byte of arr) {
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
}
});
return btoa(bin.join(''));
}

Expand Down
4 changes: 2 additions & 2 deletions integration/simple/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,9 @@ const btoa: (bin: string) => string =
globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr: Uint8Array): string {
const bin: string[] = [];
for (const byte of arr) {
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
}
});
return btoa(bin.join(''));
}

Expand Down
4 changes: 2 additions & 2 deletions integration/simple/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2357,9 +2357,9 @@ const btoa: (bin: string) => string =
globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr: Uint8Array): string {
const bin: string[] = [];
for (const byte of arr) {
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
}
});
return btoa(bin.join(''));
}

Expand Down
4 changes: 2 additions & 2 deletions integration/use-optionals-all/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,9 @@ const btoa: (bin: string) => string =
globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr: Uint8Array): string {
const bin: string[] = [];
for (const byte of arr) {
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
}
});
return btoa(bin.join(''));
}

Expand Down
4 changes: 2 additions & 2 deletions integration/value/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,9 @@ const btoa: (bin: string) => string =
globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr: Uint8Array): string {
const bin: string[] = [];
for (const byte of arr) {
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
}
});
return btoa(bin.join(''));
}

Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,9 @@ function makeByteUtils() {
const btoa : (bin: string) => string = ${globalThis}.btoa || ((bin) => ${globalThis}.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr: Uint8Array): string {
const bin: string[] = [];
for (const byte of arr) {
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
}
});
return btoa(bin.join(''));
}
`
Expand Down

0 comments on commit c7641ce

Please sign in to comment.