简体   繁体   English

在特定索引位置解码 base64 数组

[英]Decode base64 array at specific index positions

I handle a big number of XML files, each of which stores a float64 array in the form of a base64 string.我处理了大量的 XML 文件,每个文件都以 base64 字符串的形式存储一个 float64 数组。 For each of these files, I would like to access the value of its array at a specific index without loading the whole array.对于这些文件中的每一个,我想在不加载整个数组的情况下访问其数组在特定索引处的值。 I wish to do this in Python.我希望在 Python 中执行此操作。

Currently, I decode the entire string and then access the value at given index, but I am looking for a much faster method.目前,我解码整个字符串,然后访问给定索引处的值,但我正在寻找一种更快的方法。

As I understand, each float uses 8 bytes to store.据我了解,每个浮点数使用 8 个字节来存储。 Each 3-bytes of binary data are mapped to 4 base64 chars.每 3 字节的二进制数据映射到 4 个 base64 字符。 So, in order to access i-th float, you'll need to:因此,为了访问第 i 个浮点数,您需要:

  • get base64 chars from index (i * 8 / 3) * 4 to (i * 8) / 3) * 4 + 4从索引(i * 8 / 3) * 4(i * 8) / 3) * 4 + 4获取 base64 字符
  • decode that chunk from base64 to binary将该块从 base64 解码为二进制
  • drop first (i * 8) % 3 bytes先删除(i * 8) % 3个字节
  • use next 8 bytes as a float64 value.使用接下来的 8 个字节作为 float64 值。

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

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