Back to EIP

PatternMessage sequence sends the data as a sequence of messages and marks each message with sequence identification fields.
How Ballerina helps

Ballerina supports loop constructs such as while, foreach, and map. These constructs can be used to iterate over data and send it in chunks. Program state can be kept in variables.

Message SequenceMessage ChannelMessage EndpointMessage
import ballerina/http;
import ballerina/io;

final http:Client s3Client = check new ("");

public function main() returns error? {
    http:Response metaData = check s3Client->/employee_names.head();
    int fileSize = check int:fromString(check metaData.getHeader("Content-Length"));

    check io:fileWriteBytes("./resources/employee_names.txt", []);

    int numberOfChunks = (fileSize + 10 - 1) / 10;
    // Download the data chunk by chunk.
    foreach int i in 0 ..< numberOfChunks {
        map<string> headers = {Range: string `bytes=${10 * i}-${10 * (i + 1) - 1}`};
        http:Response s3Response = check s3Client->/employee_names.get(headers = headers);
        byte[] chunkData = check s3Response.getBinaryPayload();
        check io:fileWriteBytes("./resources/employee_names.txt", chunkData, io:APPEND);