Skip to content

Commit

Permalink
Add gzip demo
Browse files Browse the repository at this point in the history
  • Loading branch information
AlttiRi committed Jun 17, 2024
1 parent 65508da commit 3439ed8
Show file tree
Hide file tree
Showing 3 changed files with 333 additions and 2 deletions.
11 changes: 9 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
},
"devDependencies": {
"@alttiri/util-node-js": "2.0.16-20240606",
"fflate": "0.8.2",
"typescript": "5.5.1-rc"
}
}
323 changes: 323 additions & 0 deletions tests/gzip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,323 @@
import {deflateSync} from "fflate";
import {arrayBufferToBinaryString, utf8StringToArrayBuffer} from "./util.js";
import {encodeBase85} from "../base85.js";

/** @type {string} */
const text = getHrefTakerLinksText();

/** @type {Uint8Array} */
const compressed_text = deflateSync(utf8StringToArrayBuffer(text));
console.log(new Blob([text]).size); // 14080
console.log(new Blob([compressed_text]).size); // 3037

/** @type {string} */
const base85_compressed_text = encodeBase85(compressed_text);
const base64_compressed_text = btoa(arrayBufferToBinaryString(compressed_text));
console.log(base85_compressed_text.length); // 3797
console.log(base64_compressed_text.length); // 4052


function getLoremText() {
return ""
+
`[32] Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos, qui ratione voluptatem sequi nesciunt, neque porro quisquam est, qui dolorem ipsum, quia dolor sit amet consectetur adipisci[ng] velit, sed quia non numquam [do] eius modi tempora inci[di]dunt, ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum[d] exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? [D]Quis autem vel eum i[r]ure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur?`
+
`[33] At vero eos et accusamus et iusto odio dignissimos ducimus, qui blanditiis praesentium voluptatum deleniti atque corrupti, quos dolores et quas molestias excepturi sint, obcaecati cupiditate non provident, similique sunt in culpa, qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem reru[d]um facilis est e[r]t expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio, cumque nihil impedit, quo minus id, quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellend[a]us. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet, ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.`
;
}

function getHrefTakerLinksText() {
// Links from https://en.wikipedia.org/wiki/Main_Page
return ""
+
`https://en.wikipedia.org/wiki/Main_Page#bodyContent
https://en.wikipedia.org/wiki/Main_Page
https://en.wikipedia.org/wiki/Wikipedia:Contents
https://en.wikipedia.org/wiki/Portal:Current_events
https://en.wikipedia.org/wiki/Special:Random
https://en.wikipedia.org/wiki/Wikipedia:About
https://en.wikipedia.org/wiki/Wikipedia:Contact_us
https://donate.wikimedia.org/wiki/Special:FundraiserRedirector?utm_source=donate&utm_medium=sidebar&utm_campaign=C13_en.wikipedia.org&uselang=en
https://en.wikipedia.org/wiki/Help:Contents
https://en.wikipedia.org/wiki/Help:Introduction
https://en.wikipedia.org/wiki/Wikipedia:Community_portal
https://en.wikipedia.org/wiki/Special:RecentChanges
https://en.wikipedia.org/wiki/Wikipedia:File_upload_wizard
https://en.wikipedia.org/wiki/Special:Search
https://en.wikipedia.org/w/index.php?title=Special:CreateAccount&returnto=Main+Page
https://en.wikipedia.org/w/index.php?title=Special:UserLogin&returnto=Main+Page
https://en.wikipedia.org/wiki/Special:MyContributions
https://en.wikipedia.org/wiki/Special:MyTalk
https://en.wikipedia.org/wiki/Talk:Main_Page
https://en.wikipedia.org/w/index.php?title=Main_Page&action=edit
https://en.wikipedia.org/w/index.php?title=Main_Page&action=history
https://en.wikipedia.org/wiki/Special:WhatLinksHere/Main_Page
https://en.wikipedia.org/wiki/Special:RecentChangesLinked/Main_Page
https://en.wikipedia.org/wiki/Wikipedia:File_Upload_Wizard
https://en.wikipedia.org/wiki/Special:SpecialPages
https://en.wikipedia.org/w/index.php?title=Main_Page&oldid=1225315602
https://en.wikipedia.org/w/index.php?title=Main_Page&action=info
https://en.wikipedia.org/w/index.php?title=Special:CiteThisPage&page=Main_Page&id=1225315602&wpFormIdentifier=titleform
https://en.wikipedia.org/w/index.php?title=Special:UrlShortener&url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FMain_Page
https://en.wikipedia.org/w/index.php?title=Special:QrCode&url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FMain_Page
https://www.wikidata.org/wiki/Special:EntityPage/Q5296
https://en.wikipedia.org/w/index.php?title=Special:DownloadAsPdf&page=Main_Page&action=show-download-screen
https://en.wikipedia.org/w/index.php?title=Main_Page&printable=yes
https://commons.wikimedia.org/wiki/Main_Page
https://foundation.wikimedia.org/wiki/Home
https://www.mediawiki.org/wiki/MediaWiki
https://meta.wikimedia.org/wiki/Main_Page
https://outreach.wikimedia.org/wiki/Main_Page
https://species.wikimedia.org/wiki/Main_Page
https://en.wikibooks.org/wiki/Main_Page
https://www.wikidata.org/wiki/Wikidata:Main_Page
https://www.wikifunctions.org/wiki/Wikifunctions:Main_Page
https://wikimania.wikimedia.org/wiki/Wikimania
https://en.wikinews.org/wiki/Main_Page
https://en.wikiquote.org/wiki/Main_Page
https://en.wikisource.org/wiki/Main_Page
https://en.wikiversity.org/wiki/Wikiversity:Main_Page
https://en.wikivoyage.org/wiki/Main_Page
https://en.wiktionary.org/wiki/Wiktionary:Main_Page
https://en.wikipedia.org/wiki/Wikipedia
https://en.wikipedia.org/wiki/Free_content
https://en.wikipedia.org/wiki/Encyclopedia
https://en.wikipedia.org/wiki/Help:Introduction_to_Wikipedia
https://en.wikipedia.org/wiki/Special:Statistics
https://en.wikipedia.org/wiki/English_language
https://en.wikipedia.org/wiki/File:043_S%C3%A6var_fr%C3%A1_Stangarholti.jpg
https://en.wikipedia.org/wiki/Icelandic_horse
https://en.wikipedia.org/wiki/Horse_breed
https://en.wikipedia.org/wiki/Settlement_of_Iceland
https://en.wikipedia.org/wiki/Horse_gait
https://en.wikipedia.org/wiki/Ambling_gait#T%C3%B6lt
https://en.wikipedia.org/wiki/Horse_show
https://en.wikipedia.org/wiki/Horse_racing
https://en.wikipedia.org/wiki/Selective_breeding
https://en.wikipedia.org/wiki/Natural_selection
https://en.wikipedia.org/wiki/Laki
https://en.wikipedia.org/wiki/Whisky_Galore!_(1949_film)
https://en.wikipedia.org/wiki/Death_of_Kevin_Gately
https://en.wikipedia.org/wiki/The_Spider_(magazine)
https://en.wikipedia.org/wiki/Wikipedia:Today%27s_featured_article/June_2024
https://lists.wikimedia.org/postorius/lists/daily-article-l.lists.wikimedia.org/
https://en.wikipedia.org/wiki/Wikipedia:Featured_articles
https://en.wikipedia.org/wiki/Wikipedia:About_Today%27s_featured_article
https://en.wikipedia.org/wiki/File:Henry_Street_southern_salamander_tunnel_west_entrance,_Cushman_MA_(cropped_and_adjusted).jpg
https://en.wikipedia.org/wiki/Henry_Street_salamander_tunnels
https://en.wikipedia.org/wiki/Joe_Shield
https://en.wikipedia.org/wiki/Vermont
https://en.wikipedia.org/wiki/NFL_draft
https://en.wikipedia.org/wiki/National_Football_League
https://en.wikipedia.org/wiki/Emily_Anderson
https://en.wikipedia.org/wiki/Hush_WAACs
https://en.wikipedia.org/wiki/GCHQ#Government_Code_and_Cypher_School
https://en.wikipedia.org/wiki/Mia_Goth
https://en.wikipedia.org/wiki/Pearl_(X)
https://en.wikipedia.org/wiki/X_(2022_film)
https://en.wikipedia.org/wiki/Manganese_nitrides
https://en.wikipedia.org/wiki/Metal_foam
https://en.wikipedia.org/wiki/Jan_Leike
https://en.wikipedia.org/wiki/AI_safety
https://en.wikipedia.org/wiki/OpenAI
https://en.wikipedia.org/wiki/Zombie_Plane
https://en.wikipedia.org/wiki/Chuck_Norris
https://en.wikipedia.org/wiki/Two_Roosters_Ice_Cream
https://en.wikipedia.org/wiki/Frederick_Seguier_Drake
https://en.wikipedia.org/wiki/Daxinzhuang
https://en.wikipedia.org/wiki/Wikipedia:Recent_additions
https://en.wikipedia.org/wiki/Help:Your_first_article
https://en.wikipedia.org/wiki/Template_talk:Did_you_know
https://en.wikipedia.org/wiki/File:Saulos_Chilima.jpg
https://en.wikipedia.org/wiki/2024_Mangaf_building_fire
https://en.wikipedia.org/wiki/Kuwait_City
https://en.wikipedia.org/wiki/Mangaf
https://en.wikipedia.org/wiki/2024_Chikangawa_Dornier_228_crash
https://en.wikipedia.org/wiki/Chikangawa
https://en.wikipedia.org/wiki/Saulos_Chilima
https://en.wikipedia.org/wiki/Tennis
https://en.wikipedia.org/wiki/Iga_%C5%9Awi%C4%85tek
https://en.wikipedia.org/wiki/2024_French_Open_%E2%80%93_Women%27s_singles
https://en.wikipedia.org/wiki/Carlos_Alcaraz
https://en.wikipedia.org/wiki/2024_French_Open_%E2%80%93_Men%27s_singles
https://en.wikipedia.org/wiki/2024_French_Open
https://en.wikipedia.org/wiki/2024_Indian_general_election
https://en.wikipedia.org/wiki/National_Democratic_Alliance
https://en.wikipedia.org/wiki/Narendra_Modi
https://en.wikipedia.org/wiki/Israel%E2%80%93Hamas_war
https://en.wikipedia.org/wiki/Timeline_of_the_Israel%E2%80%93Hamas_war_(7_May_2024_%E2%80%93_present)
https://en.wikipedia.org/wiki/Russian_invasion_of_Ukraine
https://en.wikipedia.org/wiki/Timeline_of_the_Russian_invasion_of_Ukraine_(1_April_2024_%E2%80%93_present)
https://en.wikipedia.org/wiki/Sudanese_civil_war_(2023%E2%80%93present)
https://en.wikipedia.org/wiki/Timeline_of_the_Sudanese_civil_war_(2024)
https://en.wikipedia.org/wiki/Deaths_in_2024
https://en.wikipedia.org/wiki/Mike_Downey_(columnist)
https://en.wikipedia.org/wiki/Siri_Kannangara
https://en.wikipedia.org/wiki/Brad_Dusek
https://en.wikipedia.org/wiki/Matija_Sarkic
https://en.wikipedia.org/wiki/Neil_Goldschmidt
https://en.wikipedia.org/wiki/Majed_Abu_Maraheel
https://en.wikipedia.org/wiki/Wikipedia:In_the_news/Candidates
https://en.wikipedia.org/wiki/June_17
https://en.wikipedia.org/wiki/File:Portrait_of_Mumtaz_Mahal_on_Ivory_(cropped).jpg
https://en.wikipedia.org/wiki/1579
https://en.wikipedia.org/wiki/Francis_Drake
https://en.wikipedia.org/wiki/California
https://en.wikipedia.org/wiki/New_Albion
https://en.wikipedia.org/wiki/1631
https://en.wikipedia.org/wiki/Mumtaz_Mahal
https://en.wikipedia.org/wiki/List_of_emperors_of_the_Mughal_Empire
https://en.wikipedia.org/wiki/Shah_Jahan
https://en.wikipedia.org/wiki/Origins_and_architecture_of_the_Taj_Mahal
https://en.wikipedia.org/wiki/Taj_Mahal
https://en.wikipedia.org/wiki/1919
https://en.wikipedia.org/wiki/Epsom_riot
https://en.wikipedia.org/wiki/1952
https://en.wikipedia.org/wiki/Guatemalan_Revolution
https://en.wikipedia.org/wiki/Congress_of_the_Republic_of_Guatemala
https://en.wikipedia.org/wiki/Decree_900
https://en.wikipedia.org/wiki/M._C._Escher
https://en.wikipedia.org/wiki/Richard_Gagnon
https://en.wikipedia.org/wiki/Amari_Cooper
https://en.wikipedia.org/wiki/Mohamed_Morsi
https://en.wikipedia.org/wiki/June_16
https://en.wikipedia.org/wiki/June_18
https://en.wikipedia.org/wiki/Wikipedia:Selected_anniversaries/June
https://en.wikipedia.org/wiki/List_of_days_of_the_year
https://en.wikipedia.org/wiki/File:Michael_Arndt,_2007.jpg
https://en.wikipedia.org/wiki/Toy_Story_3
https://en.wikipedia.org/wiki/Comedy_drama
https://en.wikipedia.org/wiki/Pixar
https://en.wikipedia.org/wiki/Walt_Disney_Pictures
https://en.wikipedia.org/wiki/List_of_accolades_received_by_Toy_Story_3
https://en.wikipedia.org/wiki/Michael_Arndt
https://en.wikipedia.org/wiki/83rd_Academy_Awards
https://en.wikipedia.org/wiki/Academy_Award_for_Best_Picture
https://en.wikipedia.org/wiki/Academy_Award_for_Best_Animated_Feature
https://en.wikipedia.org/wiki/Academy_Award_for_Best_Original_Song
https://en.wikipedia.org/wiki/We_Belong_Together_(Randy_Newman_song)
https://en.wikipedia.org/wiki/64th_British_Academy_Film_Awards
https://en.wikipedia.org/wiki/BAFTA_Award_for_Best_Adapted_Screenplay
https://en.wikipedia.org/wiki/BAFTA_Award_for_Best_Special_Visual_Effects
https://en.wikipedia.org/wiki/BAFTA_Award_for_Best_Animated_Film
https://en.wikipedia.org/wiki/Golden_Globe_Award_for_Best_Animated_Feature_Film
https://en.wikipedia.org/wiki/68th_Golden_Globe_Awards
https://en.wikipedia.org/wiki/Grade_I_listed_buildings_in_England_completed_in_the_20th_century
https://en.wikipedia.org/wiki/SZA_discography
https://en.wikipedia.org/wiki/List_of_premiers_of_Victoria
https://en.wikipedia.org/wiki/Wikipedia:Today%27s_featured_list/June_2024
https://en.wikipedia.org/wiki/Wikipedia:Featured_lists
https://en.wikipedia.org/wiki/File:Sugarloaf_Sunrise_2.jpg
https://en.wikipedia.org/wiki/Sugarloaf_Mountain
https://en.wikipedia.org/wiki/Rio_de_Janeiro
https://en.wikipedia.org/wiki/Sugarloaf
https://en.wikipedia.org/wiki/Monolith
https://en.wikipedia.org/wiki/Bornhardt
https://en.wikipedia.org/wiki/Sugarloaf_Cable_Car
https://en.wikipedia.org/wiki/Tijuca_National_Park
https://en.wikipedia.org/wiki/Botafogo
https://en.wikipedia.org/wiki/Template:POTD/2024-06-16
https://en.wikipedia.org/wiki/Template:POTD/2024-06-15
https://en.wikipedia.org/wiki/Template:POTD/2024-06-14
https://en.wikipedia.org/wiki/Wikipedia:Picture_of_the_day/Archive
https://en.wikipedia.org/wiki/Wikipedia:Featured_pictures
https://en.wikipedia.org/wiki/Wikipedia:Village_pump
https://en.wikipedia.org/wiki/Wikipedia:News
https://en.wikipedia.org/wiki/Wikipedia:Teahouse
https://en.wikipedia.org/wiki/Wikipedia:Help_desk
https://en.wikipedia.org/wiki/Wikipedia:Reference_desk
https://en.wikipedia.org/wiki/Wikipedia:Contents/Portals
https://en.wikipedia.org/wiki/Wikimedia_Foundation
https://wikimediafoundation.org/our-work/wikimedia-projects/
https://commons.wikimedia.org/wiki/
https://www.mediawiki.org/wiki/
https://meta.wikimedia.org/wiki/
https://en.wikibooks.org/wiki/
https://www.wikidata.org/wiki/
https://en.wikinews.org/wiki/
https://en.wikiquote.org/wiki/
https://en.wikisource.org/wiki/
https://species.wikimedia.org/wiki/
https://en.wikiversity.org/wiki/
https://en.wikivoyage.org/wiki/
https://en.wiktionary.org/wiki/
https://meta.wikimedia.org/wiki/List_of_Wikipedias
https://ar.wikipedia.org/wiki/
https://arz.wikipedia.org/wiki/
https://de.wikipedia.org/wiki/
https://es.wikipedia.org/wiki/
https://fa.wikipedia.org/wiki/
https://fr.wikipedia.org/wiki/
https://it.wikipedia.org/wiki/
https://nl.wikipedia.org/wiki/
https://ja.wikipedia.org/wiki/
https://pl.wikipedia.org/wiki/
https://pt.wikipedia.org/wiki/
https://ru.wikipedia.org/wiki/
https://sv.wikipedia.org/wiki/
https://uk.wikipedia.org/wiki/
https://vi.wikipedia.org/wiki/
https://zh.wikipedia.org/wiki/
https://id.wikipedia.org/wiki/
https://ms.wikipedia.org/wiki/
https://zh-min-nan.wikipedia.org/wiki/
https://bg.wikipedia.org/wiki/
https://ca.wikipedia.org/wiki/
https://cs.wikipedia.org/wiki/
https://da.wikipedia.org/wiki/
https://eo.wikipedia.org/wiki/
https://eu.wikipedia.org/wiki/
https://he.wikipedia.org/wiki/
https://hy.wikipedia.org/wiki/
https://ko.wikipedia.org/wiki/
https://hu.wikipedia.org/wiki/
https://no.wikipedia.org/wiki/
https://ro.wikipedia.org/wiki/
https://simple.wikipedia.org/wiki/
https://sr.wikipedia.org/wiki/
https://sh.wikipedia.org/wiki/
https://fi.wikipedia.org/wiki/
https://tr.wikipedia.org/wiki/
https://uz.wikipedia.org/wiki/
https://ast.wikipedia.org/wiki/
https://az.wikipedia.org/wiki/
https://bn.wikipedia.org/wiki/
https://bs.wikipedia.org/wiki/
https://ckb.wikipedia.org/wiki/
https://et.wikipedia.org/wiki/
https://el.wikipedia.org/wiki/
https://fy.wikipedia.org/wiki/
https://ga.wikipedia.org/wiki/
https://gl.wikipedia.org/wiki/
https://hr.wikipedia.org/wiki/
https://ka.wikipedia.org/wiki/
https://ku.wikipedia.org/wiki/
https://lv.wikipedia.org/wiki/
https://lt.wikipedia.org/wiki/
https://ml.wikipedia.org/wiki/
https://mk.wikipedia.org/wiki/
https://my.wikipedia.org/wiki/
https://nn.wikipedia.org/wiki/
https://pa.wikipedia.org/wiki/
https://sq.wikipedia.org/wiki/
https://sk.wikipedia.org/wiki/
https://sl.wikipedia.org/wiki/
https://th.wikipedia.org/wiki/
https://te.wikipedia.org/wiki/
https://ur.wikipedia.org/wiki/
https://en.wikipedia.org/wiki/Wikipedia:Text_of_the_Creative_Commons_Attribution-ShareAlike_4.0_International_License
https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Terms_of_Use
https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy
https://www.wikimediafoundation.org/
https://en.wikipedia.org/wiki/Wikipedia:General_disclaimer
https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Universal_Code_of_Conduct
https://developer.wikimedia.org/
https://stats.wikimedia.org/#/en.wikipedia.org
https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Cookie_statement
https://en.m.wikipedia.org/w/index.php?title=Main_Page&mobileaction=toggle_view_mobile
https://wikimediafoundation.org/
https://www.mediawiki.org/
https://en.wikipedia.org/wiki/Main_Page?action=edit
`
;
}

0 comments on commit 3439ed8

Please sign in to comment.