[{"data":1,"prerenderedAt":852},["ShallowReactive",2],{"navigation_docs":3,"-guide-compressing":84,"-guide-compressing-surround":847},[4,48],{"title":5,"path":6,"stem":7,"children":8,"icon":47},"Guide","\u002Fguide","1.guide\u002F01.index",[9,11,15,19,23,27,31,35,39,43],{"title":10,"path":6,"stem":7},"Getting Started",{"title":12,"path":13,"stem":14},"Compressing","\u002Fguide\u002Fcompressing","1.guide\u002F02.compressing",{"title":16,"path":17,"stem":18},"Containers","\u002Fguide\u002Fcontainers","1.guide\u002F03.containers",{"title":20,"path":21,"stem":22},"Checksums","\u002Fguide\u002Fchecksums","1.guide\u002F04.checksums",{"title":24,"path":25,"stem":26},"Identify and peel","\u002Fguide\u002Fidentify","1.guide\u002F05.identify",{"title":28,"path":29,"stem":30},"Limits","\u002Fguide\u002Flimits","1.guide\u002F06.limits",{"title":32,"path":33,"stem":34},"CLI","\u002Fguide\u002Fcli","1.guide\u002F07.cli",{"title":36,"path":37,"stem":38},"Agents","\u002Fguide\u002Fagents","1.guide\u002F08.agents",{"title":40,"path":41,"stem":42},"Custom formats","\u002Fguide\u002Fcustom","1.guide\u002F09.custom",{"title":44,"path":45,"stem":46},"Playground","\u002Fguide\u002Fplayground","1.guide\u002F10.playground","i-lucide-book-open",{"title":49,"path":50,"stem":51,"children":52,"icon":83},"Formats","\u002Fformats","2.formats\u002F00.index",[53,55,59,63,67,71,75,79],{"title":54,"path":50,"stem":51},"Every format",{"title":56,"path":57,"stem":58},"deflate","\u002Fformats\u002Fdeflate","2.formats\u002F01.deflate",{"title":60,"path":61,"stem":62},"bzip2","\u002Fformats\u002Fbzip2","2.formats\u002F02.bzip2",{"title":64,"path":65,"stem":66},"LZMA","\u002Fformats\u002Flzma","2.formats\u002F03.lzma",{"title":68,"path":69,"stem":70},"Zstandard","\u002Fformats\u002Fzstd","2.formats\u002F04.zstd",{"title":72,"path":73,"stem":74},"Brotli","\u002Fformats\u002Fbrotli","2.formats\u002F05.brotli",{"title":76,"path":77,"stem":78},"LZ4","\u002Fformats\u002Flz4","2.formats\u002F06.lz4",{"title":80,"path":81,"stem":82},"Unix compress","\u002Fformats\u002Flzw","2.formats\u002F07.lzw","i-lucide-library",{"id":85,"title":86,"body":87,"description":839,"extension":840,"links":841,"meta":842,"navigation":844,"path":13,"seo":845,"stem":14,"__hash__":846},"docs\u002F1.guide\u002F02.compressing.md","Compressing and decompressing",{"type":88,"value":89,"toc":831},"minimark",[90,95,212,234,289,293,300,410,466,486,490,500,503,548,551,555,562,589,600,604,616,658,761,764,768,802,827],[91,92,94],"h2",{"id":93},"two-calls","Two calls",[96,97,102],"pre",{"className":98,"code":99,"language":100,"meta":101,"style":101},"language-ts shiki shiki-themes compressions compressions compressions","import { compress, decompress } from \"@agntn\u002Fcompressions\";\n\nconst packed = compress(\"lzma\", \"hello world!\", { container: \"xz\", level: 9 });\nconst { bytes, details } = decompress(\"lzma\", packed, { container: \"xz\" });\n\ndetails;  \u002F\u002F { check: \"crc64\", blocks: 1 }\n","ts","",[103,104,105,128,135,172,197,202],"code",{"__ignoreMap":101},[106,107,110,114,118,121,125],"span",{"class":108,"line":109},"line",1,[106,111,113],{"class":112},"skH_V","import",[106,115,117],{"class":116},"s38Sx"," { compress, decompress } ",[106,119,120],{"class":112},"from",[106,122,124],{"class":123},"shU9J"," \"@agntn\u002Fcompressions\"",[106,126,127],{"class":116},";\n",[106,129,131],{"class":108,"line":130},2,[106,132,134],{"emptyLinePlaceholder":133},true,"\n",[106,136,138,141,144,147,151,154,157,160,163,166,169],{"class":108,"line":137},3,[106,139,140],{"class":112},"const",[106,142,143],{"class":116}," packed ",[106,145,146],{"class":112},"=",[106,148,150],{"class":149},"sK71F"," compress",[106,152,153],{"class":116},"(",[106,155,156],{"class":123},"\"lzma\"",[106,158,159],{"class":116},", ",[106,161,162],{"class":123},"\"hello world!\"",[106,164,165],{"class":116},", { container: ",[106,167,168],{"class":123},"\"xz\"",[106,170,171],{"class":116},", level: 9 });\n",[106,173,175,177,180,182,185,187,189,192,194],{"class":108,"line":174},4,[106,176,140],{"class":112},[106,178,179],{"class":116}," { bytes, details } ",[106,181,146],{"class":112},[106,183,184],{"class":149}," decompress",[106,186,153],{"class":116},[106,188,156],{"class":123},[106,190,191],{"class":116},", packed, { container: ",[106,193,168],{"class":123},[106,195,196],{"class":116}," });\n",[106,198,200],{"class":108,"line":199},5,[106,201,134],{"emptyLinePlaceholder":133},[106,203,205,208],{"class":108,"line":204},6,[106,206,207],{"class":116},"details;  ",[106,209,211],{"class":210},"scIB-","\u002F\u002F { check: \"crc64\", blocks: 1 }\n",[213,214,215,218,219,222,223,226,227,229,230,233],"p",{},[103,216,217],{},"compress(name, input, options)"," takes a string, read as UTF-8, or a ",[103,220,221],{},"Uint8Array",". ",[103,224,225],{},"decompress(name, data, options)"," takes a ",[103,228,221],{}," and hands back ",[103,231,232],{},"{ bytes, details }",". That's the whole API you need on day one.",[213,235,236,237,159,240,243,244,247,248,159,250,253,254,159,257,253,260,159,263,243,266,269,270,273,274,277,278,281,282,284,285,288],{},"The name forgives you. ",[103,238,239],{},"BZIP2",[103,241,242],{},"bz2"," and ",[103,245,246],{},".bz2"," all find ",[103,249,60],{},[103,251,252],{},"zst"," finds ",[103,255,256],{},"zstd",[103,258,259],{},"br",[103,261,262],{},"brotli",[103,264,265],{},"compress",[103,267,268],{},"z"," find ",[103,271,272],{},"lzw",". What it won't do is guess a container for you: ",[103,275,276],{},"gzip"," is a container, so ",[103,279,280],{},"decompress(\"gzip\", …)"," throws and tells you to write ",[103,283,56],{}," with ",[103,286,287],{},"container: \"gzip\"",".",[91,290,292],{"id":291},"options","Options",[213,294,295,296,299],{},"Each format declares what it takes, and ",[103,297,298],{},"info()"," lists it. Anything else is an error, never silently dropped.",[301,302,303,315],"table",{},[304,305,306],"thead",{},[307,308,309,313],"tr",{},[310,311,312],"th",{},"Format",[310,314,292],{},[316,317,318,342,353,371,387,399],"tbody",{},[307,319,320,325],{},[321,322,323],"td",{},[103,324,56],{},[321,326,327,330,331,334,335,243,338,341],{},[103,328,329],{},"container"," (raw, zlib, gzip), ",[103,332,333],{},"level"," 0 to 9, ",[103,336,337],{},"name",[103,339,340],{},"mtime"," for gzip",[307,343,344,348],{},[321,345,346],{},[103,347,60],{},[321,349,350,352],{},[103,351,333],{}," 1 to 9, the block size in hundreds of kilobytes",[307,354,355,360],{},[321,356,357],{},[103,358,359],{},"lzma",[321,361,362,364,365,334,367,370],{},[103,363,329],{}," (alone, xz), ",[103,366,333],{},[103,368,369],{},"check"," for xz",[307,372,373,378],{},[321,374,375],{},[103,376,377],{},"lz4",[321,379,380,382,383,386],{},[103,381,329],{}," (frame, legacy), ",[103,384,385],{},"checksum"," for the frame",[307,388,389,393],{},[321,390,391],{},[103,392,272],{},[321,394,395,398],{},[103,396,397],{},"bits"," 10 to 16",[307,400,401,407],{},[321,402,403,159,405],{},[103,404,256],{},[103,406,262],{},[321,408,409],{},"none, this package reads them",[96,411,413],{"className":98,"code":412,"language":100,"meta":101,"style":101},"compress(\"deflate\", \"x\", { name: \"a.txt\" });\n\u002F\u002F InvalidOptionError: Invalid option name=a.txt: only gzip takes it, not raw\n\ncompress(\"deflate\", \"x\", { levl: 9 });\n\u002F\u002F InvalidOptionError: Invalid option levl=9: deflate takes container, level, name, mtime\n",[103,414,415,437,442,446,461],{"__ignoreMap":101},[106,416,417,419,421,424,426,429,432,435],{"class":108,"line":109},[106,418,265],{"class":149},[106,420,153],{"class":116},[106,422,423],{"class":123},"\"deflate\"",[106,425,159],{"class":116},[106,427,428],{"class":123},"\"x\"",[106,430,431],{"class":116},", { name: ",[106,433,434],{"class":123},"\"a.txt\"",[106,436,196],{"class":116},[106,438,439],{"class":108,"line":130},[106,440,441],{"class":210},"\u002F\u002F InvalidOptionError: Invalid option name=a.txt: only gzip takes it, not raw\n",[106,443,444],{"class":108,"line":137},[106,445,134],{"emptyLinePlaceholder":133},[106,447,448,450,452,454,456,458],{"class":108,"line":174},[106,449,265],{"class":149},[106,451,153],{"class":116},[106,453,423],{"class":123},[106,455,159],{"class":116},[106,457,428],{"class":123},[106,459,460],{"class":116},", { levl: 9 });\n",[106,462,463],{"class":108,"line":199},[106,464,465],{"class":210},"\u002F\u002F InvalidOptionError: Invalid option levl=9: deflate takes container, level, name, mtime\n",[213,467,468,471,472,474,475,243,478,481,482,288],{},[103,469,470],{},"decompress"," takes only the options marked to read with, which is ",[103,473,329],{}," and nothing else. Plus ",[103,476,477],{},"limit",[103,479,480],{},"partial",", which every format takes, see ",[483,484,485],"a",{"href":29},"limits",[91,487,489],{"id":488},"levels","Levels",[213,491,492,494,495,497,498,288],{},[103,493,333],{}," means what the format's own tool means by it. deflate follows zlib's ten levels, from 0 (stored, nothing compressed) to 9 (longest search). The default is 6, same as ",[103,496,276],{},". lzma follows the xz presets: the level picks the dictionary size, 256 KiB at 0 up to 64 MiB at 9, and how hard it searches. bzip2's level is the block size, and 9 is the default, same as ",[103,499,60],{},[213,501,502],{},"On a kilobyte of repeated text deflate gives:",[301,504,505,515],{},[304,506,507],{},[307,508,509,512],{},[310,510,511],{},"Level",[310,513,514],{},"Bytes",[316,516,517,525,533,541],{},[307,518,519,522],{},[321,520,521],{},"0",[321,523,524],{},"1025, stored blocks",[307,526,527,530],{},[321,528,529],{},"1",[321,531,532],{},"32",[307,534,535,538],{},[321,536,537],{},"6",[321,539,540],{},"26",[307,542,543,546],{},[321,544,545],{},"9",[321,547,540],{},[213,549,550],{},"Higher levels mostly pay off on bigger, messier input. Small text tops out fast.",[91,552,554],{"id":553},"what-decompress-gives-back","What decompress gives back",[213,556,557,558,561],{},"Bytes, always. And ",[103,559,560],{},"details",", the facts the stream carried about itself:",[96,563,565],{"className":98,"code":564,"language":100,"meta":101,"style":101},"decompress(\"deflate\", gz, { container: \"gzip\" }).details;\n\u002F\u002F { name: \"notes.txt\", mtime: 1700000000, os: 255, members: 1 }\n",[103,566,567,584],{"__ignoreMap":101},[106,568,569,571,573,575,578,581],{"class":108,"line":109},[106,570,470],{"class":149},[106,572,153],{"class":116},[106,574,423],{"class":123},[106,576,577],{"class":116},", gz, { container: ",[106,579,580],{"class":123},"\"gzip\"",[106,582,583],{"class":116}," }).details;\n",[106,585,586],{"class":108,"line":130},[106,587,588],{"class":210},"\u002F\u002F { name: \"notes.txt\", mtime: 1700000000, os: 255, members: 1 }\n",[213,590,591,592,595,596,599],{},"Every format reads every stream in a row, the way its own tool does. Two gzip members come out as one, and ",[103,593,594],{},"members"," says 2. Bytes after the last stream that aren't another stream show up as ",[103,597,598],{},"trailing",", with how many. Zero padding after gzip is fine and isn't counted, since tapes did that.",[91,601,603],{"id":602},"format-objects-and-subpaths","Format objects and subpaths",[213,605,606,607,159,609,159,611,243,613,615],{},"Every format is an object with ",[103,608,337],{},[103,610,298],{},[103,612,265],{},[103,614,470],{},". The registry functions just look the object up by name. Import the object straight from its own subpath and plain Node loads that format and nothing else:",[96,617,619],{"className":98,"code":618,"language":100,"meta":101,"style":101},"import { deflate } from \"@agntn\u002Fcompressions\u002Fdeflate\";\n\ndeflate.compress(\"hi\", { container: \"zlib\" });\n",[103,620,621,635,639],{"__ignoreMap":101},[106,622,623,625,628,630,633],{"class":108,"line":109},[106,624,113],{"class":112},[106,626,627],{"class":116}," { deflate } ",[106,629,120],{"class":112},[106,631,632],{"class":123}," \"@agntn\u002Fcompressions\u002Fdeflate\"",[106,634,127],{"class":116},[106,636,637],{"class":108,"line":130},[106,638,134],{"emptyLinePlaceholder":133},[106,640,641,644,646,648,651,653,656],{"class":108,"line":137},[106,642,643],{"class":116},"deflate.",[106,645,265],{"class":149},[106,647,153],{"class":116},[106,649,650],{"class":123},"\"hi\"",[106,652,165],{"class":116},[106,654,655],{"class":123},"\"zlib\"",[106,657,196],{"class":116},[301,659,660,670],{},[304,661,662],{},[307,663,664,667],{},[310,665,666],{},"Subpath",[310,668,669],{},"Exports",[316,671,672,686,697,714,725,736,750],{},[307,673,674,679],{},[321,675,676],{},[103,677,678],{},"@agntn\u002Fcompressions\u002Fdeflate",[321,680,681,159,683],{},[103,682,56],{},[103,684,685],{},"DEFLATE_CONTAINERS",[307,687,688,693],{},[321,689,690],{},[103,691,692],{},"@agntn\u002Fcompressions\u002Fbzip2",[321,694,695],{},[103,696,60],{},[307,698,699,704],{},[321,700,701],{},[103,702,703],{},"@agntn\u002Fcompressions\u002Flzma",[321,705,706,159,708,159,711],{},[103,707,359],{},[103,709,710],{},"LZMA_CONTAINERS",[103,712,713],{},"XZ_CHECKS",[307,715,716,721],{},[321,717,718],{},[103,719,720],{},"@agntn\u002Fcompressions\u002Fzstd",[321,722,723],{},[103,724,256],{},[307,726,727,732],{},[321,728,729],{},[103,730,731],{},"@agntn\u002Fcompressions\u002Fbrotli",[321,733,734],{},[103,735,262],{},[307,737,738,743],{},[321,739,740],{},[103,741,742],{},"@agntn\u002Fcompressions\u002Flz4",[321,744,745,159,747],{},[103,746,377],{},[103,748,749],{},"LZ4_CONTAINERS",[307,751,752,757],{},[321,753,754],{},[103,755,756],{},"@agntn\u002Fcompressions\u002Flzw",[321,758,759],{},[103,760,272],{},[213,762,763],{},"They're the same objects the root exports, not copies. The brotli one is the heavy one, since it carries the 122,784 byte dictionary of RFC 7932, deflated. Nothing else loads it.",[91,765,767],{"id":766},"errors","Errors",[213,769,770,771,774,775,778,779,782,783,786,787,789,790,793,794,797,798,801],{},"Every error is a ",[103,772,773],{},"CompressionError",". A broken stream throws ",[103,776,777],{},"DecompressError",", with the ",[103,780,781],{},"format",", the ",[103,784,785],{},"offset"," in the input when one byte is at fault, and ",[103,788,480],{},", everything that came out before the damage. Its subclasses say more: ",[103,791,792],{},"ChecksumError"," for a stream that decoded but doesn't check, ",[103,795,796],{},"LimitError"," for output past the limit, ",[103,799,800],{},"UnsupportedError"," for a valid stream using something this package doesn't do, like a zstd dictionary or the xz ARM filter.",[96,803,805],{"className":98,"code":804,"language":100,"meta":101,"style":101},"decompress(\"deflate\", flipped, { container: \"gzip\" });\n\u002F\u002F ChecksumError: deflate: gzip CRC-32 does not match at byte 24\n",[103,806,807,822],{"__ignoreMap":101},[106,808,809,811,813,815,818,820],{"class":108,"line":109},[106,810,470],{"class":149},[106,812,153],{"class":116},[106,814,423],{"class":123},[106,816,817],{"class":116},", flipped, { container: ",[106,819,580],{"class":123},[106,821,196],{"class":116},[106,823,824],{"class":108,"line":130},[106,825,826],{"class":210},"\u002F\u002F ChecksumError: deflate: gzip CRC-32 does not match at byte 24\n",[828,829,830],"style",{},"html pre.shiki code .skH_V, html code.shiki .skH_V{--shiki-light:var(--shiki-token-keyword);--shiki-default:var(--shiki-token-keyword);--shiki-dark:var(--shiki-token-keyword)}html pre.shiki code .s38Sx, html code.shiki .s38Sx{--shiki-light:var(--ui-text-highlighted);--shiki-default:var(--ui-text-highlighted);--shiki-dark:var(--ui-text-highlighted)}html pre.shiki code .shU9J, html code.shiki .shU9J{--shiki-light:var(--shiki-token-string);--shiki-default:var(--shiki-token-string);--shiki-dark:var(--shiki-token-string)}html pre.shiki code .sK71F, html code.shiki .sK71F{--shiki-light:var(--shiki-token-function);--shiki-default:var(--shiki-token-function);--shiki-dark:var(--shiki-token-function)}html pre.shiki code .scIB-, html code.shiki .scIB-{--shiki-light:var(--shiki-token-comment);--shiki-default:var(--shiki-token-comment);--shiki-dark:var(--shiki-token-comment)}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":101,"searchDepth":130,"depth":130,"links":832},[833,834,835,836,837,838],{"id":93,"depth":130,"text":94},{"id":291,"depth":130,"text":292},{"id":488,"depth":130,"text":489},{"id":553,"depth":130,"text":554},{"id":602,"depth":130,"text":603},{"id":766,"depth":130,"text":767},"Two calls for every format. Options and levels and the format objects and one subpath per format","md",null,{"icon":843},"i-lucide-arrow-right-left",{"title":12},{"title":86,"description":839},"3D8H5ZJp0GnQ5gxrZcvIZ2Fciv3QrgnxtzW7rodtoSw",[848,850],{"title":10,"path":6,"stem":7,"description":849,"children":-1},"Install the package and open your first gzip file. Every format answers the same two calls",{"title":16,"path":17,"stem":18,"description":851,"children":-1},"gzip and zlib and raw deflate are one compression in three wrappers. Why that's an option and what each wrapper adds",1791071141269]