wolfram-mathematica - 如何在 InputStream 上执行 Get?

标签 wolfram-mathematica drm

编码包的一件烦人的事情是它们必须在一个单独的文件中。如果我们要分发一个简单的自包含应用程序(编码),我们需要提供两个文件:应用程序“接口(interface)”和应用程序包。

如果我将编码文件的所有内容放在一个字符串中,并将该字符串转换为 InputStream,我就可以将包内容视为一个文件。

但是 Get,据我所知,这是唯一具有解码功能的操作(也由 Needs 使用),不适用于 Streams。它仅适用于真实文件。

有人能想出一个获取流的方法吗?

最佳答案

等待 Mathematica 到达我的 iPhone 所以无法测试任何东西,但你为什么不将字符串写入一个临时文件并获取它呢?

更新

这是如何做到的:

encoded = ToFileName[$TemporaryDirectory, "encoded"];

Export[encoded, "code string", "Text"]; (*export encrypted code to temp file *)

使用 ASCII 编辑器从包含编码代码的 ASCII 文件中复制代码字符串的内容并将其粘贴在现有的空引号 ("") 之间非常重要。然后 Mathematica 将自动转义代码中可能存在的反斜杠和引号。这个文件之前是用 Encode 制作的。 .无法在示例代码中执行此操作,因为 SO 的 Markdown 与字符串混淆。
Get[encoded] (* get encrypted code and decode *) 

DeleteFile[encoded] (* Remove temp  file *)

最终答案
Get似乎不需要解码。 ImportString也可以:
ImportString["code string", "NB"] 

如上所述,将 ASCII 编辑器中的编码 tekst 直接粘贴在“”之间,然后让 MMA 进行转义。

enter image description here

关于wolfram-mathematica - 如何在 InputStream 上执行 Get?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7220033/

相关文章:

android - Exoplayer 错误中的 Widevine Drm

php - 如何防止用户直接下载 MP3

html - 如何使用 Clear Key 加密 webm 文件以使用 Google 的 Shaka Player 播放?

wolfram-mathematica - 重复图案

wolfram-mathematica - Mathematica 中 LocatorPane 图形上的右键单击菜单

wolfram-mathematica - 如何指定 Wolframalpha 图中哪个轴上的哪个变量?

math - 计算点到线段和线段到线段的平均距离

python-3.x - IPython Notebook 有 "initialization cells"吗?

iphone - 是否可以检查设备是否越狱?