将 Blob 数据从 SQLite 数据库保存到文件

发布于 2024-08-31 05:52:45 字数 1023 浏览 1 评论 0原文

我试图将 SQLite 数据库(Safari 缓存:Cache.db)中的 blob 数据保存到文件中,但由于某种原因 sqlite 不会读取整个 blob。我最终想在 ruby​​ 中执行此操作,但现在直接在 sqlite 命令提示符中运行的东西就可以了。另外,我已经阅读了 stackoverflow 上讨论此问题的所有条目,但其中大多数只讨论了将图像保存在 blob 中的性能,而确实显示将 blob 保存到文件的一个条目是用 C# 编写的,这没有帮助我。这是我尝试过的:

sqlite>从cfurl_cache_response限制1中选择*; 3501|0|945281827|0|http://www .gospelz.com/components/com_jomcomment/smilies/guest.gif|2010-02-24 16:20:07

sqlite>从cfurl_cache_blob_data中选择receiver_data,其中entry_ID = 3501;
GIF89a(

原始 (guest.gif) 文件的十六进制转储显示 sqlite 在第一个空值之后停止读取 blob:

$ hexdump -C guest.gif
00000000 47 49 46 38 39 61 28 00 28 00 f7 00 00 f1 f5 fd |GIF89a(.(.......|

sqlite> .输出测试.gif
sqlite>从cfurl_cache_blob_data中选择receiver_data,其中entry_ID = 3501;
$ hexdump -C test.gif
00000000 47 49 46 38 39 61 28 0a |GIF89a(.|

I'm trying to save blob data from a SQLite database (Safari cache: Cache.db) to a file, but for some reason sqlite won't read the whole blob. I eventually would like to do this in ruby, but for now something that works directly in sqlite command prompt is fine. Also, I've read all of the entries that talk about this here on stackoverflow, but most of them only discuss the performance of saving images in blobs and the one entry that does show to save blobs to file is in C# which does not help me. Here is what I've tried:

sqlite> select * from cfurl_cache_response limit 1;
3501|0|945281827|0|http://www.gospelz.com/components/com_jomcomment/smilies/guest.gif|2010-02-24 16:20:07

sqlite> select receiver_data from cfurl_cache_blob_data where entry_ID = 3501;
GIF89a(

A hexdump of the original (guest.gif) file shows that sqlite stops reading the blob after the first null value:

$ hexdump -C guest.gif
00000000 47 49 46 38 39 61 28 00 28 00 f7 00 00 f1 f5 fd |GIF89a(.(.......|

sqlite> .output test.gif
sqlite> select receiver_data from cfurl_cache_blob_data where entry_ID = 3501;
$ hexdump -C test.gif
00000000 47 49 46 38 39 61 28 0a |GIF89a(.|

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

滴情不沾 2024-09-07 05:52:45

SQLite3 正在读取整个 blob,但 sqlite shell 程序仅显示直到 NUL。

要测试这一点,您可以尝试:

select hex( receiver_data ) from cfurl_cache_blob_data where entry_ID = 3501;

SQLite3 is reading the whole blob, but the sqlite shell program is only displaying up to the NUL.

To test this you can try:

select hex( receiver_data ) from cfurl_cache_blob_data where entry_ID = 3501;
挖鼻大婶 2024-09-07 05:52:45

在 Ruby 中,从 blob 或原始二进制文件生成文件非常简单。您可以按照写入文件的方式进行操作。例如,要创建 jpeg:

File.open("image_name.jpg", 'w') {|f| f.write raw_blob_content } 

Generating a file from a blob or raw binary is pretty straight forward in Ruby. You do it the same way you'd write to a file. For example, to create a jpeg:

File.open("image_name.jpg", 'w') {|f| f.write raw_blob_content } 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文