ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
138 stars 56 forks source link

Add data binding support for FTP client #4234

Open dilanSachi opened 1 year ago

dilanSachi commented 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);
dilanSachi commented 3 months ago

We can also support a list of a record types etc.

Person[] person = check caller->get(addedFile.path);