Yesterday I asked a similar question about the filestream method, What is the Python equivalent to FileStream in C#?, but I now realize I should have probably been asking about the .read function instead.
For context I am trying to consume a streamed response from a soap API, which should output a CSV file. The response outputs a string coded in base 64, which I do not know what to do with. Also the api documentation says that the response must be read to a destination buffer-by-buffer.
Here is the context in the code. The code was provided by the api's documentation:
byte[] buffer = new byte[4000];
bool endOfStream = false;
int bytesRead = 0;
using (FileStream localFileStream = new FileStream(destinationPath, FileMode.Create, FileAccess.Write))
{
using (Stream remoteStream = client.DownloadFile(jobId, chkFormatAsXml.Unchecked))
{
while (!endOfStream)
{
bytesRead = remoteStream.Read(buffer, 0, buffer.Length);
if (bytesRead > 0)
{
localFileStream.Write(buffer, 0, bytesRead);
totalBytes += bytesRead;
}
else
{
endOfStream = true;
}
}
}
}
Any help would be greatly appreciated, even if it is just to point me in the right direction, as I am very lost now. I also, had another question referencing the same problem today as well. Write Streamed Response(file-like object) to CSV file Byte by Byte in Python