简体   繁体   English

如何将 Julia stream 转换为 Python ZEFE90A8E604A7C840E7BZ 的“字节内容”?

[英]How I do convert a Julia stream to "byte content" for a Python package?

I maintain OdsIo.jl , a Julia package that wraps, for ods files specifically, ezodf , a Python package for various OpenDocument formats, I maintain OdsIo.jl , a Julia package that wraps, for ods files specifically, ezodf , a Python package for various OpenDocument formats,

My "ods_readall" function starts by calling ezodf.opendoc .我的“ods_readall” function 从调用ezodf.opendoc开始。

ezodf.opendoc supports as input, other than the filename, the file byte content itself: ezodf.opendoc支持作为输入,除了文件名,文件字节内容本身:

ezodf.opendoc(filename)¶
    Parameters: filename (str) – a filename or the file-content as bytes

Is there a way I can use it with a Julia stream (eg a network gzipped file as in this question ) intead of plain files?有没有办法可以将它与 Julia stream (例如这个问题中的网络压缩文件)而不是普通文件一起使用?

This seems to work, at least for HTTP, that is what I was interested to:这似乎有效,至少对于 HTTP,这就是我感兴趣的:

using HTTP, Pipe, PyCall

const  pyio  = PyNULL()
const  ezodf = PyNULL()

copy!(pyio, pyimport("io"))
copy!(ezodf, pyimport("ezodf"))

function readstream(istream)
    return ezodf.opendoc(pyio.BytesIO(istream))
end

urlData = "https://github.com/sylvaticus/OdsIO.jl/raw/master/test/spreadsheet.ods"

doc = @pipe HTTP.get(urlData).body |> readstream(_)

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

相关问题 如何将python元组(字节数组)的一部分转换为整数 - How do I convert part of a python tuple (byte array) into an integer 如何在python中将Integer转换为ctypes.c_byte - How do I convert an Integer to ctypes.c_byte in python 如何在Python中将字节数组转换为位图图像? - How do I convert byte array to bitmap image in Python? 如何使用python将我的字节数据转换为整数? - How do I convert my byte data to integer using python? 如何在 python 3 中将字节文字列表转换为字符串文字? - How do I convert a list of byte literals into string literals in python 3? 有一个 python 字节(来自 img),我如何在 C# 中处理它,并转换为字节 [] 或图像 stream? - There is a python bytes( from img) , how can I handle it in C# ,and convert to a byte[ ] or a image stream? 如何将文件 stream 转换为 Python 中的数据 URI? - How do I convert a file stream to a data URI in Python? Python:如何将存储在字节流中的 CSV 文件转换为列表? - Python : How to convert a CSV file stored in Byte stream to a List? 如何在Python 3中将文本流编码为字节流? - How to encode a text stream into a byte stream in Python 3? 我如何在 python 3.5 及更高版本中将奇数长度的十六进制字符串转换为字节格式? - how do i convert odd length hexadecimal string to byte format in python 3.5 and above?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM