Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8833983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:54:47+00:00 2026-06-14T08:54:47+00:00

Some pieces of our app are written in Ruby and others are written using

  • 0

Some pieces of our app are written in Ruby and others are written using node.js.

We share data among them using a redis store that stores zlib chunks.
We write to it with the following code using node:

zlib.deflate(xml.toString(), function(error, deflated) {
  ...
  deflated.toString('binary'); // That's the string we write in Redis
  ...
});

Now, we read this data in the redis store using Ruby (1.8.7) and I have to say I’m not sure how to do that.

The typical string we get from the store looks like this:

=> "xuAo \020ÿ\ná.£v½\030dÿCO½±:«¤(\004ƪÿ¾¬®5MÚ\003÷½IÞ q¤°²e°c¼òÈ×\000ó<ùM¸ÐAç\025ÜÈ\r|gê\016Ý/.é\020ãÆî×\003Ôç<Ýù2´F\n¨Å\020!zl \0209\034p|üÀqò\030\036m\020\e`\031¼ÏütÓ=ø¦U/ÔO±\177zB{\037½£-ðBu©ò¢X\000kb­*Ó[V\024Y^½EÎ¥üpúrò­¦\177ÁÃdÈ¢j\0353$a\027²q#¥]*Ýi3J8¤´füd\eså[³öʵ%\fcÇY\037ð¬ÿg§í^¥8£Õ§a¶\001=\r;¡¾\001\020Pí" 

Of course, I tried using Zlib::Inflate.new.inflate(compressed) but that fails with a Zlib::DataError: incorrect header check.

Any idea on what kind of transformation we should do to that string to inflate it from Ruby?

PS: inflating it from node is easy and works, so the problem is not how we compress it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:54:48+00:00Added an answer on June 14, 2026 at 8:54 am

    Any idea on what kind of transformation we should do to that string to
    inflate it from Ruby?

    UTF-8 to Latin-1

    Ideally, there would be no need for any transformation, as long as you work with Buffers directly on the Node side. See pair of Node and Ruby code blocks at the very bottom below; however, the nature of the question is about what can be done on the Ruby side alone to address this.

    Ruby-only – Convert from UTF-8 to LATIN-1

    require 'zlib'
    require 'rubygems'
    require 'redis'
    require 'iconv'
    
    redis = Redis.new
    
    def inflate(buffer)
        zstream = Zlib::Inflate.new
        buf = zstream.inflate(buffer)
        zstream.finish
        zstream.close
        buf
    end
    
    
    def convert(buffer)
        utf8_to_latin1 = Iconv.new("LATIN1//TRANSLIT//IGNORE", "UTF8")
        utf8_to_latin1.iconv(buffer) 
    end
    
    value = redis.get("testkey")
    value = convert(value)
    puts inflate(value);
    

    Explanation

    The above code uses iconv to convert the value retrieved from Redis from UTF-8 back to the intended bytes.

    When deflating in Node, the resulting buffer contains the correct zlib generated bytes; the result string from toString('binary'), character for character matches the contents of the deflate result buffer as well; however, by the time the deflate result is stored in Redis, it is UTF-8 encoded. An example:

    deflating the string “ABCABC” results in:

    <Buffer 78 9c 73 74 72 76 74 72 06 00 05 6c 01 8d>
    

    Yet, Redis returns:

    <Buffer 78 c2 9c 73 74 72 76 74 72 06 00 05 6c 01 c2 8d>
    

    Hypothesizing a bit, it would seem that the string resulting from toString('binary') ends up as argument to new Buffer(…) somewhere, perhaps in node-redis. In the absence of a specified encoding argument to new Buffer(), the default UTF-8 encoding is applied. (See first reference). Further hypothesizing, by using only buffers you avoid the need to create a buffer from the string, and as a result, avoid the UTF8 encoding, and so the correct deflate values make it in and out of Redis.

    References

    • http://nodejs.org/api/buffer.html#buffer_new_buffer_str_encoding
    • http://blog.grayproductions.net/articles/encoding_conversion_with_iconv
    • http://ruby-doc.org/stdlib-1.8.7/libdoc/zlib/rdoc/Zlib/Inflate.html.

    Node

    var zlib = require('zlib');
    var redis = require("redis").createClient();
    
    var message = new Buffer('your stuff goes here.');
    //var message = new Buffer(xml.toString());
    
    redis.on("error", function (err) {
    console.log("Error " + err);
    });
    
    redis.on("connect", function() {
        console.log(message);
        zlib.deflate(message, function(error, deflated) {
            console.log(deflated);          
            redis.set("testkey",deflated,function (err, reply) {
                console.log(reply.toString());
            });
        });
    });
    

    Ruby

    require 'zlib'
    require 'rubygems'
    require 'redis'
    
    redis = Redis.new
    
    def inflate(buffer)
        zstream = Zlib::Inflate.new
        buf = zstream.inflate(buffer)
        zstream.finish
        zstream.close
        buf
    end
    
    value = redis.get("testkey")    
    
    puts inflate(value)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written some extension modules for eJabberd most of which pass pieces of
I'm in the middle of trying to upgrade pieces of our app to Rails
I want to add some jQuery functionality to our sites where one piece of
I am planning a script to manage some pieces of my Linux systems and
I want to extensively test some pieces of C code for memory leaks. On
I was looking over some of our JavaScript compression and noticed that no strings
We want to move our database to SQL azure. I'm using SQLAzureMW tool v3.8
I've been tasked with automating the collection of some reports from our remote locations.
Currently i am working on a project using prism where one of our modules
I am developing initscripts for some of our software, and am having difficulty deciding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.