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 1059537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:11:18+00:00 2026-05-16T18:11:18+00:00

I am trying to GZip content in a variable to output to the browser.

  • 0

I am trying to GZip content in a variable to output to the browser. To start I am making this very simple and not worrying about browsers that do not support gzip. Also I have put this together from researching several methods that I could find on the web. Some of them from people that may be reading this question.

<cfsavecontent variable="toGZIP"><html><head><title>Test</title></head><body><h1>Fear my test</h1></body></html></cfsavecontent>

<cfscript>
ioOutput = CreateObject("java","java.io.ByteArrayOutputStream");
gzOutput = CreateObject("java","java.util.zip.GZIPOutputStream");

ioOutput.init();
gzOutput.init(ioOutput);

gzOutput.write(toGZIP.getBytes("UTF-8"), 0, Len(toGZIP.getBytes()));

gzOutput.finish();
gzOutput.close();
ioOutput.flush();
ioOutput.close();

toOutput=ioOutput.toString("UTF-8");
</cfscript>

<cfcontent reset="yes" /><cfheader name="Content-Encoding" value="gzip"><cfheader name="Content-Length" value="#ArrayLen( toOuptut.getBytes() )#" ><cfoutput>#toOuptut#</cfoutput><cfabort />

But I get an error in Firefox (and chrome and Safari)

Content Encoding Error

The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.

Anybody have any ideas?

OS: Mac OX-X Snow Leopard
CF: 9-Dev
Webserver: Apache


SOLUTION

<cfsavecontent variable="toGZIP"><html><head><title>Test</title></head><body><h1>Fear my test</h1></body></html></cfsavecontent>

<cfscript>
ioOutput = CreateObject("java","java.io.ByteArrayOutputStream");
gzOutput = CreateObject("java","java.util.zip.GZIPOutputStream");

ioOutput.init();
gzOutput.init(ioOutput);

gzOutput.write(toGZIP.getBytes(), 0, Len(toGZIP.getBytes()));

gzOutput.finish();
gzOutput.close();
ioOutput.flush();
ioOutput.close();

toOutput=ioOutput.toByteArray();
</cfscript>

<cfheader name="Content-Encoding" value="gzip"><cfheader name="Content-Length" value="#ArrayLen(toOutput)#" ><cfcontent reset="yes" variable="#toOutput#" /><cfabort />
  • 1 1 Answer
  • 2 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-05-16T18:11:19+00:00Added an answer on May 16, 2026 at 6:11 pm

    The follow line look completely wrong:

    toOutput=ioOutput.toString("UTF-8");
    

    You encode the GZip stream with UTF8. The result are garbage data. The best you set the GZip data as binary if ColdFusion has the option. If you can only set a string then you need an encoding that not change any bytes. For example iso1.

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

Sidebar

Related Questions

I'm trying to make Gzip compression work on xampp, right now this is in
Trying to make a call and retrieve a very simple, one line, JSON file.
I am trying to GZIP some XML that gets streamed over HTTP (not a
I'm trying to gzip responses from GAE server, but receive null in Content-Encoding. I
Im trying to provide gzip compression using varnish cache. But when I set content-encoding
I am trying to fetch a gzip from a URL and import it automatically
I am trying to send a gzip ed multipart POST to a Tomcat server
I was trying to change the compression of some gzip files from the default
I am trying to encode a list as JSON, compress it using gzip in
Using Google App Engine, I am trying to urlfetch a gzip file from a

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.