# Compressed Ruby for Embedded Devices

**URL:** <https://www.ruby-forum.com/t/compressed-ruby-for-embedded-devices/96951>\
**Category:** Ruby\
**Created:** [July 3, 2006, 6:49pm UTC](https://www.ruby-forum.com/t/compressed-ruby-for-embedded-devices/96951 "2006-07-03T18:49:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonsaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@simonsaid](https://www.ruby-forum.com/u/simonsaid)\
**Post date:** [July 3, 2006, 6:49pm UTC](https://www.ruby-forum.com/t/compressed-ruby-for-embedded-devices/96951/1 "2006-07-03T18:49:47Z")

</div>

Hello,

Let me give you some background, We have embedded devices such as FOX  
VHDL ([FOX VHDL a FPGA development board for the FOX Board](http://www.acmesystems.it/?id=120)). It runs fully functional linux  
kernel on which we have the ruby interpretor and a bunch of ruby  
scripts. All is well except for we are running out of storage, we only  
get 8MB.

Now we need to front our growing number of ruby scripts with a web  
interface, most likely \_why’s Camping framework or some custom CGI.

So due to space limitations I thought the best thing to do would be  
compress the ruby files and decompress them at runtime. Performance  
should be ok since the number of simultaneous users is throttled anyway.

I had two thoughts;

1. Build decompression in to the interpreter, I have looked through the  
source (1.8.4)and it looks like I might be able to hook in to load\_file,  
and do something like decompress the file and pass the decompressed  
contents to load\_stdin (is this how code sent using -e is processed?).

2. Override require in the Kernel. I’m taking a bit of guess here  
because I cant actually find require.rb, but I’m guessing the file being  
required is simply eval’d so I could decompress the file and eval it in  
place mimicking the behavior of the normal require.

It would also be of more value if I used a different extension for  
compressed ruby, maybe .crb, that way I can look for the compressed ruby  
file first and if it does not exist look for a plain ruby file.

Does this seem reasonable? Any short comings?

Many thanks, Simon.

---

<div class="post-metadata">

**Author:** ![simonsaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@simonsaid](https://www.ruby-forum.com/u/simonsaid)\
**Post date:** [July 6, 2006, 12:32pm UTC](https://www.ruby-forum.com/t/compressed-ruby-for-embedded-devices/96951/2 "2006-07-06T12:32:26Z")

</div>

Simon S. wrote:

> Hello,
> 
> Let me give you some background, We have embedded devices such as FOX  
> VHDL ([http://www.acmesystems.it/?id=120](http://www.acmesystems.it/?id=120)). It runs fully functional linux  
> kernel on which we have the ruby interpretor and a bunch of ruby  
> scripts. All is well except for we are running out of storage, we only  
> get 8MB.

I thought this might catch peoples eye, but by the no replies, clearly  
not.

---

<div class="post-metadata">

**Author:** ![simonsaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@simonsaid](https://www.ruby-forum.com/u/simonsaid)\
**Post date:** [July 6, 2006, 1:36pm UTC](https://www.ruby-forum.com/t/compressed-ruby-for-embedded-devices/96951/3 "2006-07-06T13:36:32Z")

</div>

On 06/07/06, Simon S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I thought this might catch peoples eye, but by the no replies, clearly  
> not.

I actually did think it was fairly interesting. I suspect that you  
could do it by patching load\_file in ruby.c to look for magic and  
decompress the file if appropriate.

Paul.
