我需要为一组应用程序(桌面/在线/移动..)重新设计文件格式,其中包含一组非线性数据和多个图像。
我不想让它成为一个带有嵌入图像的大型 XML,因为:
- 首先它可能会增长到使用 javascript 解析速度很慢的大小,
- 其次我希望它可以“手动”编辑。
压缩是不必要的。我只想将其作为单个文件分发。我希望我的解决方案尽可能跨平台。
我最近制作的是一个 *.tar.gz 存档,里面有 xml 和图像。
- 我的应用程序的桌面(C++/Qt)版本正在使用 zlib 读取文件(这很难编码,但可以工作)。
- 在线版本使用 PHP(执行 tar)解压缩文件(将内容缓存在数据库中)并通过 ajax 将 xml 和图像传递给 javascript。
- 当我开始开发 Android 版本时,我有点卡住了,我不知道如何在这里阅读它。
我想知道是否有更好/更简单的解决方案来实现这一目标?
我找到的解决方案例如:
可能没有“最好的方法”来做到这一点,但我希望有一些广泛使用的解决方案?
我将不胜感激对此的任何想法。
I need to redesign a file format for a set of applications ( desktop/online/mobile.. ) which is to contain a set of non-linear data and multiple images.
I do not want to make it one large XML with embedded images as:
- first of all it could grow to a size that would be for example slow to parse using javascript
- second of all I want it to be editable 'by hand'.
The compression is not necessary. I just want to distribute this as a single files. I would like my solution to be as cross-platform as possible.
What I made up recently is a *.tar.gz archive with xmls and images inside.
- The desktop (C++ / Qt) version of my application is reading the file using zlib (which was hard to code but works).
- The online version is using PHP (execing tar) to uncompress the file (caches contents in database) and passes xmls and images to javascript via ajax.
- When I came to develop an android version I'm kinda stuck and I don't know how to read it here.
I was wondering if there is a better / simpler solution to achieve this?
Solutions I found are for example:
- Blender .blend files http://en.wikipedia.org/wiki/Blender_%28software%29#File_format But this is not readable without any special tool.
- OpenOffice files which are in fact zips.
But I guess there is no big difference using this or tar.gz. It still would be a problem to read it on a mobile platform or with javascript.
Probably there is no 'best way' to do this but i hope there are some widely used solutions?
I will appreciate any thoughts on this.
发布评论
评论(2)
我不确定这是否符合您的“可手动编辑”标准,但要制作单文件、跨平台的二进制格式,Google Protocol Buffers 非常有用且高效,并且可以跨主要平台和语言工作。
如果“手动编辑”很重要,那么只需做一些额外的工作,您就可以使用自己的消息库编写简单的实用程序来支持创建/更新/删除现有文件的部分(例如提取图像进行编辑,并支持替换它们。)
I'm not sure if this will meet your "editable by hand" criteria, but to make a single-file, cross-platform binary format, Google Protocol Buffers are very useful and efficient, and work across major platforms and languages.
If "editable by hand" is critical, with a little extra work, you can write simple utilities using your own message libraries to support creating/updating/deleting portions of existing files (e.g. extract out images for editing, and support replacing them.)
如果它必须可以在 JavaScript 中编辑,也许 JSON 可能是一个不错的选择?您可以使用base64数据url编码插入图片/视频/其他文件,Javascript和许多其他语言都支持这种编码。
If it must be editable in JavaScript, perhaps JSON might be a good option? You can insert pictures/video/other files by using base64 data url encoding, which is supported in Javascript and many other languages.