Skip to content

Commit

Permalink
Use correct data types in FileReaderTurboModule::ReadAs* (#11902)
Browse files Browse the repository at this point in the history
* Use ReadAs* data argument as JSValueObject

* Change files
  • Loading branch information
JunielKatarn authored Jul 18, 2023
1 parent 00d2242 commit df09b65
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Use correct data types in FileReaderTurboModule::ReadAs*",
"packageName": "react-native-windows",
"email": "julio.rocha@microsoft.com",
"dependentChangeType": "patch"
}
41 changes: 26 additions & 15 deletions vnext/Shared/Modules/FileReaderModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,26 @@ void FileReaderTurboModule::Initialize(msrn::ReactContext const &reactContext) n
}

///
/// <param name="args">
/// Array of arguments passed from the JavaScript layer.
/// [0] - dynamic blob object { blobId, offset, size[, type] }
/// <param name="data">
/// Blob object with the following fields:
/// - blobId
/// - offset
/// - size
/// - type (optional)
/// </param>
/// <param name="result">
/// Either resolves or rejects the current method with a given text message.
/// </param>
///
void FileReaderTurboModule::ReadAsDataUrl(msrn::JSValue &&data, msrn::ReactPromise<string> &&result) noexcept {
auto &array = data.AsArray();
auto &blob = data[0].AsObject();
auto &blob = data.AsObject();
auto blobId = blob["blobId"].AsString();
auto offset = blob["offset"].AsInt64();
auto size = blob["size"].AsInt64();

auto typeItr = blob.find("type");
string type{};
if (typeItr == blob.end()) { // TODO: .items() ?
if (typeItr == blob.end()) {
type = "application/octet-stream";
} else {
type = (*typeItr).second.AsString();
Expand All @@ -155,20 +160,26 @@ void FileReaderTurboModule::ReadAsDataUrl(msrn::JSValue &&data, msrn::ReactPromi
[&result](string &&message) { result.Reject(winrt::to_hstring(std::move(message)).c_str()); });
}

/// TODO: update (folly not used)
/// <param name="args">
/// Array of arguments passed from the JavaScript layer.
/// [0] - dynamic blob object { blobId, offset, size }
/// [1] - string encoding
/// </param>
///
/// <param name="data">
/// Blob object with the following fields:
/// - blobId
/// - offset
/// - size
/// - type (optional)
/// </param>
/// <param name="encoding">
/// Text encoding to proces data with.
/// </param>
/// <param name="result">
/// Either resolves or rejects the current method with a given text message.
/// </param>
///
void FileReaderTurboModule::ReadAsText(
msrn::JSValue &&data,
string &&encoding,
msrn::ReactPromise<string> &&result) noexcept {
auto &args = data.AsArray();
auto &blob = args[0].AsObject();

auto &blob = data.AsObject();
auto blobId = blob["blobId"].AsString();
auto offset = blob["offset"].AsInt64();
auto size = blob["size"].AsInt64();
Expand Down

0 comments on commit df09b65

Please sign in to comment.