Open dilanSachi opened 1 year ago
Description: At the moment, when we need to read a remote file content, we have to something like below.
service on remoteServer { remote function onFileChange(ftp:WatchEvent & readonly fileEvent, ftp:Caller caller) { foreach ftp:FileInfo addedFile in fileEvent.addedFiles { stream<byte[] & readonly, io:Error?> fileStream = check caller->get(addedFile.path); json|error j = fromBytesToJson(fileStream); io:println(j); } } } function fromBytesToJson(stream<byte[] & readonly, io:Error?> fileStream) returns json|error { byte[] bytes = []; check fileStream.forEach(function(byte[] & readonly block) { bytes.push(...block); }); string s = check string:fromBytes(bytes); json j = check s.fromJsonString(); return j; }
Rather than this, its better to have something as follows.
json jsonContent = check caller->get(addedFile.path); csv csvContent = check caller->get(addedFile.path); xml xmlContent = check caller->get(addedFile.path); byte[] byteContent = check caller->get(addedFile.path);
We can also support a list of a record types etc.
Person[] person = check caller->get(addedFile.path);
Description: At the moment, when we need to read a remote file content, we have to something like below.
Rather than this, its better to have something as follows.