我可以序列化ruby Digest :: SHA1实例对象吗? [英] Can I serialize a ruby Digest::SHA1 instance object?

查看:169
本文介绍了我可以序列化ruby Digest :: SHA1实例对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

'G'day人,

我正在使用redis作为后备存储的ruby(sinatra)中重新实现现有的自定义文件上传服务.

I am re-implementing an existent custom file upload service in ruby (sinatra) with redis as a backing store.

客户 计算SHA1哈希并启动上传 最多上传64K块,直到完成

Client calculates a SHA1 hash and initiates an upload uploads max 64K chunks until finished

服务器 将大块追加到文件 计算完整文件的SHA1哈希值以验证收据是否正确

Server appends chunks to file calculates SHA1 hash of complete file to verify correct receipt

现在,我希望使用ruby(1.9.3)Digest :: SHA1<< (更新)运算符,每个块(而不是必须从头开始读取整个文件). [大文件> 1GB].

Now, what I am hoping to do is use ruby (1.9.3) Digest::SHA1 << (update) operator on each chunk, (rather than having to read the ENTIRE file from scratch at the end). [Large files > 1GB].

不幸的是Digest :: SHA1和Marshal.dump不兼容

Unfortunately Digest::SHA1 and Marshal.dump aren't compatible

1.9.3p125 :001 > require 'digest'
 => true 
1.9.3p125 :002 > $digest = Digest::SHA1.new
 => #<Digest::SHA1: da39a3ee5e6b4b0d3255bfef95601890afd80709> 
1.9.3p125 :003 > marshalled_digest = Marshal.dump($digest)
TypeError: no _dump_data is defined for class Digest::SHA1
    from (irb):3:in `dump'
    from (irb):3
    from /Users/rhodry/.rvm/rubies/ruby-1.9.3-p125/bin/irb:16:in `<main>'
1.9.3p125 :004 > 

有人对如何操作有任何想法吗

Does anyone have any ideas on how to:

  1. 是否可以访问底层内存(用C语言操作)并存储/还原这样的对象?
  2. 获得允许类似用例的替代实现吗?

谢谢

参数

更新: gist:2280705 使用ruby FFI实现选项1-希望它对其他人有用

Update: gist:2280705 implements option 1 using ruby FFI - hope it is useful to someone else

推荐答案

您是否考虑过,并且能够发送64k块的SHA1?会有更多的校验和数据,但是您会知道哪里出了问题,并且不需要存储摘要的内部状态.

Have you considered and are you able to send the SHA1's of the 64k chunks? There would be more checksum data, but you would know where things went wrong, and there would be no need to store internal state of the digest.

这篇关于我可以序列化ruby Digest :: SHA1实例对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆