如何在Python中复制C#.read(buffer,0,buffer.Length)

编程入门 行业动态 更新时间:2024-10-11 01:14:06
本文介绍了如何在Python中复制C#.read(buffer,0,buffer.Length)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

昨天我问了一个关于文件流方法的类似问题, C#中的FileStream与Python等效的是什么?,但我现在意识到我应该可能会询问.read函数。

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.

对于上下文我试图使用soap API的流式响应,它应该输出一个CSV文件。响应输出一个以base 64编码的字符串,我不知道该怎么做。此外,api文档说必须将响应读取到目标缓冲区。

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.

以下是代码中的上下文。该代码由api的文档提供:

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; } } } }

任何非常感谢帮助,即使它只是指向正确的方向,因为我现在非常迷失。我还有另一个问题,现在引用同样的问题。 写入流式响应(文件 - 像对象)到CSV文件Byte by Byte in Python

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

推荐答案

它看起来像 bytesread = len(openfile.read(4000))是正确的复制方法 bytesRead = remoteStream.Read(buffer,0,buffer.Length);

It looks like bytesread = len(openfile.read(4000)) is the correct way to replicate bytesRead = remoteStream.Read(buffer, 0, buffer.Length);

谢谢DYZ

更多推荐

如何在Python中复制C#.read(buffer,0,buffer.Length)

本文发布于:2023-10-28 10:34:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1536391.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   Python   read   buffer   Length

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!