简体   繁体   English

Python与C#中的FileStream等效吗?

[英]What is the Python equivalent to FileStream in C#?

I am trying to replicate this bit of code in Python which takes a text stream encoded in base64 and writes it byte by byte to a csv file: 我正在尝试在Python中复制以下代码,该代码采用以base64编码的文本流,并将其逐字节写入csv文件:

using (FileStream localFileStream = new FileStream(destinationPath, FileMode.Create, FileAccess.Write))
{
   using (Stream remoteStream = client.DownloadFile(jobId))
   {
     while (!endOfStream)
     {
         bytesRead = remoteStream.Read(buffer, 0, buffer.Length);
         if (bytesRead > 0)
         {
              localFileStream.Write(buffer, 0, bytesRead);
              totalBytes += bytesRead;
         }
         else
         {
              endOfStream = true;
         }
      }
   }
}

Unfortunately I do not know what the equivalent of FileStreamis in Python, so I am unable to translate the code. 不幸的是,我不知道Python中FileStream的等效功能,所以我无法翻译代码。

The equivalent to C#'s FileStream is Python's file object. 与C#的FileStream等效的是Python的文件对象。 They both handle reading & writing files, and do not do any major manipulation of the data read/written. 它们都处理读取和写入文件,并且不对读取/写入的数据进行任何重大操作。 (I'm not sure what a "coded download text stream" is, but neither language's file writer is going to decode it on its own.) (我不确定“编码的下载文本流”是什么,但是两种语言的文件编写器都不会自行对其进行解码。)

(When opened in text mode, Python's file object will normalize line endings, but that's it.) (在文本模式下打开时,Python的文件对象将规范行尾,仅此而已。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM