我们有一个场景,我们在单个响应中发送多个 json 文件。这些 json 文件作为单独的 blob 存储在后端 (aerospike blobstore) 中,并根据单个请求动态获取。
只要我们发送这些未压缩的 blob,它就可以正常工作。也就是说,我们在每个 blob 之后添加一个分隔符,并使用此分隔符来隔离每个 json blob,如下所示 -
{
// first json here
}
-- JSONEND--blobid1
{
// second json here
}
-- JSONEND--blobid2
等等。
只要 blob 从源(即 blob 存储)中解压缩,它就可以正常工作,并且我们能够在解析后将 javascript 中的每个 json 隔离到一个单独的变量中。
但我们面临的挑战是 - 由于各种原因(性能/减少磁盘空间),这些 blob 被预压缩并保存到 blobstore 中,并且我们希望简单地将这些压缩的 blob 在一次响应中发送给客户端。客户端的脚本使用这些 blob 并将它们解析为单独的 json 对象树。
这可能吗?如何 ?我们只需要支持 Chrome,可能还支持 Firefox。
最佳答案
如果您使用Gzip
并且您有一个nodejs
服务器
看这里,如何使用gzjoin
gzjoin.c
join gzip files without recalculating the crc or recompressing
- illustrates the use of the Z_BLOCK flush parameter for inflate()
- illustrates the use of crc32_combine()
https://github.com/nodejs/node/tree/master/deps/zlib/examples
关于javascript - 如何在单个 http 响应中发送多个先前压缩的文件以供脚本使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46234694/