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

  • Home
  • SEARCH
  • 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 8713153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:16:23+00:00 2026-06-13T05:16:23+00:00

I’m trying to compress HTML with JavaScript and decompress it with Ruby. Some carachters

  • 0

I’m trying to compress HTML with JavaScript and decompress it with Ruby. Some carachters are not being processed correctly however and I’m looking for a way to fix this.

My compression function first turns the html in to a byte array using this function. It then compresses the array with the js-deflate library. Finally, the output from that is base64 encoded using window.btoa().

var compress = function(htmlString) {
  var compressed, originalBytes;

  originalBytes = Utils.stringToByteArray(htmlString);
  compressed = RawDeflate.deflate(originalBytes.join(''));
  return window.btoa(compressed);
};

On the Ruby end of things I have a Decompression class which first base64 decodes the compressed html. It then uses the Ruby Zlib standard library to decompress the html. This process is described in this Stack Overflow question thread.

require "base64"
require "zlib"

class Decompression
  def self.decompress(string)
    decoded = Base64.decode64(string)
    inflate(decoded)
  end

private

  def self.inflate(string)
    zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
    buf = zstream.inflate(string)
    zstream.finish
    zstream.close
    buf
  end
end

I’m using this class to inflate compressed html, which was sent to a local server, and write it to a file.

decompressed_content = Decompression.decompress(params["compressed_content"])
File.write('decompressed.html', decompressed_content)

Then I open the file in the browser to see if it looks correct.

For the most part, this works fine. I can process the Stack Overflow homepage and it comes out like this:

processed Stack Overflow homepage

You can see there is some problems though. Some characters are not coming out correctly, most notably the down arrow beside my name in the header

down arrow

and the multiplication signs in the recent tags list

recent tags list

How can I fix my code so that these parts of the page are processed properly?

I have tried to force the encoding of the inflated html to UTF-8 but it doesn’t change anything.

  def self.decompress(string)
    decoded = Base64.decode64(string)
    # Forcing the encoding of the output doesn't do anything.
    inflate(decoded).force_encoding('UTF-8')
  end

  def self.decompress(string)
    decoded = Base64.decode64(string)
    # Either does forcing the encoding of the inflate input.
    inflate(decoded.force_encoding('UTF-8'))
  end

One key is that the encoding of the string seems to change to ASCII-8BIT after it is Base64 decoded:

def self.decompress(string)
  p "Before decode: #{string.encoding}"
  decoded = Base64.decode64(string)
  p "After decode: #{decoded.encoding}"
  inflated = inflate(decoded)
  p "After inflate: #{inflated.encoding}"
  inflated
end

# Before decode: UTF-8
# After decode: ASCII-8BIT
# After inflate: ASCII-8BIT

Edits

Someone asked for the method I use to get the html in the first place. I simply pull it off the page with jQuery:

$('html')[0].outerHTML

Edit to show effect of adding a Content-Type meta tag to the inflated html

I added <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> to the inflated html. And I now get question mark boxes like this (Chrome browser by the way):

question mark box.

If I inspect the source of my inflated html and compare it to the source of the actual Stack Overflow html I can see that there is a different character being used for the upside-down triangle beside my name.

Actual SO Source: <span class="profile-triangle">&#9662;</span>
Inflated Source without meta Content-Type: <span class="profile-triangle">¾</span>
Inflated source with meta Content-Type: <span class="profile-triangle">�</span>

  • 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-13T05:16:24+00:00Added an answer on June 13, 2026 at 5:16 am

    Try adding UTF8 encoding to the HTML you get. Like in

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" charset="UTF-8" />
    

    I suggest this because I can’t actually see it in the source code (ctrl+u on this same page).

    EDIT: Turns out you were missing the charset!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.