Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Aug 30th, 2005, 6:11 PM   #11
Eryk
Programmer
 
Join Date: Jul 2005
Posts: 62
Rep Power: 4 Eryk is on a distinguished road
Quote:
Originally Posted by Cerulean
Gzip does a good job of getting text files waay down. You can then pad the data up to 400. Should be pretty easy.
Here's a template you can use when you code it in C++ - it's written in Python (solely because I got curious).
import zlib

def make400Bytes(s):
    assert len(s) > 400
    compressed = zlib.compress(s)
    if len(compressed) > 400:
        print "Ouch, data size compression problem. Dataset too big, or bad data"
        return None
    compressed = compressed + "#" * (400 - len(compressed))
    return compressed

def make600Bytes(s):
    return zlib.decompress(s.rstrip("#"))


before = """Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer at purus. Aliquam posuere nibh. Vestibulum vitae turpis non arcu venenatis luctus. Sed at nisi. Aliquam erat volutpat. Sed urna. Quisque sit amet arcu eu tellus luctus mollis. Phasellus rhoncus vulputate sem. Nunc lacinia nibh. Ut fermentum augue nec odio. Duis fringilla tincidunt elit. 
Mauris urna metus, placerat vitae, porttitor non, scelerisque et, libero. Donec nibh quam, mollis eget, placerat quis, sollicitudin in, magna. Nullam non urna. Vestibulum metus arcu, condimentum pellentesque, porttitor in, tempus ac, erat. Pelle"""
 
print "len(before) =", len(before) # 600
after = make400Bytes(before)
print "len(after) =", len(after) # down to 400
afterAfter = make600Bytes(after)
print "len(afterAfter) =", len(afterAfter) # back up to 600
I'm not sure, but I don't think the C zlib library is simple as the standard-library Python one with a "compress" and "decompress" function pair. If so, it should be quite easily to translate.
Hate to say this but I'm using javascript

I'll be sure to look at it though and see if I can apply it to JS.
Eryk is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:13 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC