Repository: expo/expo
File: packages/expo/android/src/main/java/expo/modules/fetch/ExpoFetchModule.kt (Kotlin)

Code before:
      }

      Property("_rawHeaders") { response: NativeResponse ->
        response.responseInit?.headers ?: emptyList()
      }

      Property("status") { response: NativeResponse ->
        response.responseInit?.status ?: -1
      }

      Property("statusText") { response: NativeResponse ->
        response.responseInit?.statusText ?: ""
      }

      Property("url") { response: NativeResponse ->
        response.responseInit?.url ?: ""
      }

      Property("redirected") { response: NativeResponse ->
        response.responseInit?.redirected ?: false
      }

      AsyncFunction("arrayBuffer") { response: NativeResponse, promise: Promise ->
        response.waitForStates(listOf(ResponseState.BODY_COMPLETED)) {
          val data = response.sink.finalizeDirect()
          promise.resolve(NativeArrayBuffer(data))
        }
      }

      AsyncFunction("text") { response: NativeResponse, promise: Promise ->
        response.waitForStates(listOf(ResponseState.BODY_COMPLETED)) {
          val data = response.sink.finalize()
          val text = data.toString(Charsets.UTF_8)
          promise.resolve(text)
        }
      }
    }

    Class(NativeRequest::class) {
      Constructor { response: NativeResponse ->
        return@Constructor NativeRequest(appContext, response)
      }

      AsyncFunction("start") {
          request: NativeRequest,
          url: URL,
          requestInit: NativeRequestInit,
          requestBody: ByteArray?,
          promise: Promise ->
        request.start(client, url, requestInit, requestBody)
        request.response.waitForStates(

Review comment (bug):
Previously, `data` was of type `ByteArray`, so upon returning it was converted to `Uint8Array`, effectively meaning that `response.arrayBuffer()`  was actually returning `Uint8Array` instead of `ArrayBuffer` 😬
It was not failing anywhere because Uint8Array constructor accepts another Uint8Array as an argument ([docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#typedarray)).
So `new Uint8Array(await response.arrayBuffer())` created a copy of existing array instead of a view over existing array buffer...

Code after:
      }

      Property("_rawHeaders") { response: NativeResponse ->
        response.responseInit?.headers ?: emptyList()
      }

      Property("status") { response: NativeResponse ->
        response.responseInit?.status ?: -1
      }

      Property("statusText") { response: NativeResponse ->
        response.responseInit?.statusText ?: ""
      }

      Property("url") { response: NativeResponse ->
        response.responseInit?.url ?: ""
      }

      Property("redirected") { response: NativeResponse ->
        response.responseInit?.redirected ?: false
      }

      AsyncFunction("arrayBuffer") { response: NativeResponse, promise: Promise ->
        response.waitForStates(listOf(ResponseState.BODY_COMPLETED)) {
          val data = response.sink.finalize(directBuffer = true)
          promise.resolve(NativeArrayBuffer(data))
        }
      }

      AsyncFunction("text") { response: NativeResponse, promise: Promise ->
        response.waitForStates(listOf(ResponseState.BODY_COMPLETED)) {
          val data = response.sink.finalize(directBuffer = false).array()
          val text = data.toString(Charsets.UTF_8)
          promise.resolve(text)
        }
      }
    }

    Class(NativeRequest::class) {
      Constructor { response: NativeResponse ->
        return@Constructor NativeRequest(appContext, response)
      }

      AsyncFunction("start") {
          request: NativeRequest,
          url: URL,
          requestInit: NativeRequestInit,
          requestBody: ByteArray?,
          promise: Promise ->
        request.start(client, url, requestInit, requestBody)
        request.response.waitForStates(