Index: runtime/bin/file.cc |
diff --git a/runtime/bin/file.cc b/runtime/bin/file.cc |
index f04a36796801de3ff497124e4797299c2b3d3ac7..4b6ffcf6449a64b9071701cac9f3199cf174d7aa 100644 |
--- a/runtime/bin/file.cc |
+++ b/runtime/bin/file.cc |
@@ -965,10 +965,26 @@ static CObject* FileReadListRequest(const CObjectArray& request) { |
} |
+static int SizeInBytes(Dart_CObject::ByteArrayType type) { |
+ switch (type) { |
+ case Dart_CObject::kInt8Array: |
+ case Dart_CObject::kUint8Array: |
+ return 1; |
+ case Dart_CObject::kInt16Array: |
+ case Dart_CObject::kUint16Array: |
+ return 2; |
+ default: |
+ break; |
+ } |
+ UNREACHABLE(); |
+ return -1; |
+} |
+ |
+ |
static CObject* FileWriteListRequest(const CObjectArray& request) { |
if (request.Length() == 5 && |
request[1]->IsIntptr() && |
- (request[2]->IsUint8Array() || request[2]->IsArray()) && |
+ (request[2]->IsByteArray() || request[2]->IsArray()) && |
request[3]->IsInt32OrInt64() && |
request[4]->IsInt32OrInt64()) { |
File* file = CObjectToFilePointer(request[1]); |
@@ -977,8 +993,10 @@ static CObject* FileWriteListRequest(const CObjectArray& request) { |
int64_t offset = CObjectInt32OrInt64ToInt64(request[3]); |
int64_t length = CObjectInt32OrInt64ToInt64(request[4]); |
uint8_t* buffer_start; |
- if (request[2]->IsUint8Array()) { |
- CObjectUint8Array byte_array(request[2]); |
+ if (request[2]->IsByteArray()) { |
+ CObjectByteArray byte_array(request[2]); |
+ offset = offset * SizeInBytes(byte_array.Type()); |
+ length = length * SizeInBytes(byte_array.Type()); |
buffer_start = byte_array.Buffer() + offset; |
} else { |
CObjectArray array(request[2]); |
@@ -997,7 +1015,7 @@ static CObject* FileWriteListRequest(const CObjectArray& request) { |
} |
int64_t bytes_written = |
file->Write(reinterpret_cast<void*>(buffer_start), length); |
- if (!request[2]->IsUint8Array()) { |
+ if (!request[2]->IsByteArray()) { |
delete[] buffer_start; |
} |
if (bytes_written >= 0) { |