如何在输入流上执行 Get 操作?
编码包的一件烦人的事情是它们必须位于单独的文件中。如果我们想分发一个简单的自包含应用程序(编码),我们需要提供两个文件:应用程序“界面”和应用程序包。
如果我将编码文件的所有内容放入一个字符串中,并将该字符串转换为 InputStream,那么我就将该包内容视为文件了。
但是据我所知,Get 是唯一具有解码功能的操作(也被 Needs 使用),在 Streams 上不起作用。它仅适用于真实文件。
有人能找到一种获取流的方法吗?
One annoying thing of encoded packages is that they have to be in a separate file. If we want to distribute a simple self contained app (encoded), we need to supply two files: the app "interface", and the app package.
If I place all the content of the encoded file inside a string, and transform that string into an InputStream, I'm halfway to view that package content as a file.
But Get, that to my knowledge is the only operation (also used by Needs) that has the decoding function, doesn't work on Streams. It only works on real files.
Can someone figure out a way to Get a Stream?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
等待 Mathematica 出现在我的 iPhone 上,因此无法测试任何内容,但为什么不将字符串写入临时文件并获取它呢?
更新
操作方法如下:
使用 ASCII 编辑器从包含编码代码的 ASCII 文件中复制代码字符串的内容并将其粘贴到现有的空引号 ("") 之间非常重要。然后,Mathematica 将自动转义代码中可能存在的反斜杠和引号。该文件是之前使用
Encode
创建的。无法在示例代码中执行此操作,因为 SO 的 Markdown 会混淆字符串。最终答案
Get
似乎对于解码来说不是必需的。ImportString
也能正常工作:如上所述,将 ASCII 编辑器中编码的 tekst 直接粘贴到“”之间,然后让 MMA 进行转义。
Waiting for Mathematica to arrive on my iPhone so couldn't test anything, but why don't you write the string to a temporary file and Get that?
Update
Here's how to do it:
It's important to copy the contents of the code string from the ASCII file containing the encoded code using an ASCII editor and paste it between existing empty quotes (""). Mathematica will then do automatic escaping of backslashes and quotes that may be in the code. This file has been made earlier using
Encode
. Can't do it here in the sample code as SO's Markdown messes with the string.Final Answer
Get
doesn't appear to be necessary for decoding.ImportString
does work as well:As above, paste your encoded tekst from an ASCII editor straight between the "" and let MMA do the escaping.
我不知道获取流的方法,但您可以将编码数据存储在单个包中,将其写入临时文件,然后使用 Get 读回临时文件。
I don't know of a way to Get a Stream, but you could store the encoded data in your single package, write it out to a temp file, then read the temp file back in with Get.
只是为了保持最新状态:
自 V9.0 起,
Get
可与流配合使用。Just to keep things up to date:
Get
works with streams since V9.0.