Skip to content

Commit 9e2ef4d

Browse files
authored
Merge branch 'main' into patch-1
2 parents 401fde3 + a44acf1 commit 9e2ef4d

File tree

4 files changed

+7
-21
lines changed

4 files changed

+7
-21
lines changed

src/actions/receive-profile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ async function _extractZipFromResponse(
10651065
async function _extractJsonFromArrayBuffer(
10661066
arrayBuffer: ArrayBuffer
10671067
): Promise<unknown> {
1068-
let profileBytes: Uint8Array<ArrayBufferLike> = new Uint8Array(arrayBuffer);
1068+
let profileBytes = new Uint8Array(arrayBuffer);
10691069
// Check for the gzip magic number in the header.
10701070
if (isGzip(profileBytes)) {
10711071
profileBytes = await decompress(profileBytes);

src/profile-logic/process-profile.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,9 +1980,7 @@ export async function unserializeProfileOfArbitraryFormat(
19801980
// object is constructed from an ArrayBuffer in a different context... which
19811981
// happens in our tests.
19821982
if (String(arbitraryFormat) === '[object ArrayBuffer]') {
1983-
// Obviously Flow doesn't understand that this is correct, so let's help
1984-
// Flow here.
1985-
let arrayBuffer: ArrayBufferLike = arbitraryFormat as any;
1983+
let arrayBuffer = arbitraryFormat as ArrayBuffer;
19861984

19871985
// Check for the gzip magic number in the header. If we find it, decompress
19881986
// the data first.

src/test/store/receive-profile.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe('actions/receive-profile', function () {
131131
return states;
132132
}
133133

134-
function encode(string: string): Uint8Array {
134+
function encode(string: string): Uint8Array<ArrayBuffer> {
135135
return new TextEncoder().encode(string);
136136
}
137137

src/utils/gz.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,8 @@ async function readableStreamToBuffer(
3232
return result;
3333
}
3434

35-
// The Streams API doesn't support SAB, and so we need to copy from these to
36-
// use these API's.
37-
function copyBufferIfShared(buffer: Uint8Array): Uint8Array<ArrayBuffer> {
38-
// Check if the buffer is a view into a larger ArrayBuffer (shared)
39-
if (buffer.buffer instanceof SharedArrayBuffer) {
40-
// Create a new buffer with its own ArrayBuffer
41-
return new Uint8Array(buffer);
42-
}
43-
// Return the original buffer if it's not shared
44-
return buffer as Uint8Array<ArrayBuffer>;
45-
}
46-
4735
export async function compress(
48-
data: string | Uint8Array
36+
data: string | Uint8Array<ArrayBuffer>
4937
): Promise<Uint8Array<ArrayBuffer>> {
5038
// Encode the data if it's a string
5139
const arrayData =
@@ -56,22 +44,22 @@ export async function compress(
5644

5745
// Write the data to the compression stream
5846
const writer = compressionStream.writable.getWriter();
59-
writer.write(copyBufferIfShared(arrayData));
47+
writer.write(arrayData);
6048
writer.close();
6149

6250
// Read the compressed data back into a buffer
6351
return readableStreamToBuffer(compressionStream.readable);
6452
}
6553

6654
export async function decompress(
67-
data: Uint8Array
55+
data: Uint8Array<ArrayBuffer>
6856
): Promise<Uint8Array<ArrayBuffer>> {
6957
// Create a gzip compression stream
7058
const decompressionStream = new DecompressionStream('gzip');
7159

7260
// Write the data to the compression stream
7361
const writer = decompressionStream.writable.getWriter();
74-
writer.write(copyBufferIfShared(data));
62+
writer.write(data);
7563
writer.close();
7664

7765
// Read the compressed data back into a buffer

0 commit comments

Comments
 (0)