CINXE.COM

flate package - compress/flate - Go Packages

<!DOCTYPE html> <html lang="en" data-layout="responsive" data-local=""> <head> <script> window.addEventListener('error', window.__err=function f(e){f.p=f.p||[];f.p.push(e)}); </script> <script> (function() { const theme = document.cookie.match(/prefers-color-scheme=(light|dark|auto)/)?.[1] if (theme) { document.querySelector('html').setAttribute('data-theme', theme); } }()) </script> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="Description" content="Package flate implements the DEFLATE compressed data format, described in RFC 1951."> <meta class="js-gtmID" data-gtmid="GTM-W8MVQXG"> <link rel="shortcut icon" href="/static/shared/icon/favicon.ico"> <link rel="canonical" href="https://pkg.go.dev/compress/flate"> <link href="/static/frontend/frontend.min.css?version=prod-frontend-00098-h5t" rel="stylesheet"> <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="Go Packages"> <title>flate package - compress/flate - Go Packages</title> <link href="/static/frontend/unit/unit.min.css?version=prod-frontend-00098-h5t" rel="stylesheet"> <link href="/static/frontend/unit/main/main.min.css?version=prod-frontend-00098-h5t" rel="stylesheet"> </head> <body> <script> function loadScript(src, mod = true) { let s = document.createElement('script'); s.src = src; if (mod) { s.type = 'module'; s.async = true; s.defer = true } document.head.appendChild(s); } loadScript("/third_party/dialog-polyfill/dialog-polyfill.js", false) loadScript("/static/frontend/frontend.js"); </script> <header class="go-Header go-Header--full js-siteHeader"> <div class="go-Header-inner go-Header-inner--dark"> <nav class="go-Header-nav"> <a href="https://go.dev/" class="js-headerLogo" data-gtmc="nav link" data-test-id="go-header-logo-link" role="heading" aria-level="1"> <img class="go-Header-logo" src="/static/shared/logo/go-white.svg" alt="Go"> </a> <div class="skip-navigation-wrapper"> <a class="skip-to-content-link" aria-label="Skip to main content" href="#main-content"> Skip to Main Content </a> </div> <div class="go-Header-rightContent"> <div class="go-SearchForm js-searchForm"> <form class="go-InputGroup go-ShortcutKey go-SearchForm-form" action="/search" data-shortcut="/" data-shortcut-alt="search" data-gtmc="search form" aria-label="Search for a package" role="search" > <input name="q" class="go-Input js-searchFocus" aria-label="Search for a package" type="search" autocapitalize="off" autocomplete="off" autocorrect="off" spellcheck="false" placeholder="Search packages or symbols" value="" /> <input name="m" value="" hidden> <button class="go-Button go-Button--inverted" aria-label="Submit search"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/search_gm_grey_24dp.svg" alt="" /> </button> </form> <button class="go-SearchForm-expandSearch js-expandSearch" data-gtmc="nav button" aria-label="Open search" data-test-id="expand-search"> <img class="go-Icon go-Icon--inverted" height="24" width="24" src="/static/shared/icon/search_gm_grey_24dp.svg" alt=""> </button> </div> <ul class="go-Header-menu"> <li class="go-Header-menuItem"> <a class="js-desktop-menu-hover" href="#" data-gtmc="nav link"> Why Go <img class="go-Icon" height="24" width="24" src="/static/shared/icon/arrow_drop_down_gm_grey_24dp.svg" alt="submenu dropdown icon"> </a> <ul class="go-Header-submenu go-Header-submenu--why js-desktop-submenu-hover" aria-label="submenu"> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/solutions#case-studies"> <span>Case Studies</span> </a> </div> <p>Common problems companies solve with Go</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/solutions#use-cases"> <span>Use Cases</span> </a> </div> <p>Stories about how and why companies use Go</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/security/"> <span>Security</span> </a> </div> <p>How Go can help keep you secure by default</p> </li> </ul> </li> <li class="go-Header-menuItem"> <a href="https://go.dev/learn/" data-gtmc="nav link">Learn</a> </li> <li class="go-Header-menuItem"> <a class="js-desktop-menu-hover" href="#" data-gtmc="nav link"> Docs <img class="go-Icon" height="24" width="24" src="/static/shared/icon/arrow_drop_down_gm_grey_24dp.svg" alt="submenu dropdown icon"> </a> <ul class="go-Header-submenu go-Header-submenu--docs js-desktop-submenu-hover" aria-label="submenu"> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/doc/effective_go"> <span>Effective Go</span> </a> </div> <p>Tips for writing clear, performant, and idiomatic Go code</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/doc/"> <span>Go User Manual</span> </a> </div> <p>A complete introduction to building software with Go</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://pkg.go.dev/std"> <span>Standard library</span> </a> </div> <p>Reference documentation for Go's standard library</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/doc/devel/release"> <span>Release Notes</span> </a> </div> <p>Learn what's new in each Go release</p> </li> </ul> </li> <li class="go-Header-menuItem go-Header-menuItem--active"> <a href="/" data-gtmc="nav link">Packages</a> </li> <li class="go-Header-menuItem"> <a class="js-desktop-menu-hover" href="#" data-gtmc="nav link"> Community <img class="go-Icon" height="24" width="24" src="/static/shared/icon/arrow_drop_down_gm_grey_24dp.svg" alt="submenu dropdown icon"> </a> <ul class="go-Header-submenu go-Header-submenu--community js-desktop-submenu-hover" aria-label="submenu"> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/talks/"> <span>Recorded Talks</span> </a> </div> <p>Videos from prior events</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://www.meetup.com/pro/go"> <span>Meetups</span> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/launch_gm_grey_24dp.svg" alt=""> </i> </a> </div> <p>Meet other local Go developers</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://github.com/golang/go/wiki/Conferences"> <span>Conferences</span> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/launch_gm_grey_24dp.svg" alt=""> </i> </a> </div> <p>Learn and network with Go developers from around the world</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/blog"> <span>Go blog</span> </a> </div> <p>The Go project's official blog.</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/help"> <span>Go project</span> </a> </div> <p>Get help and stay informed from Go</p> </li> <li class="go-Header-submenuItem"> <div> Get connected </div> <p></p> <div class="go-Header-socialIcons"> <a class="go-Header-socialIcon" aria-label="Get connected with google-groups (Opens in new window)" title="Get connected with google-groups (Opens in new window)" href="https://groups.google.com/g/golang-nuts"> <img src="/static/shared/logo/social/google-groups.svg" /> </a> <a class="go-Header-socialIcon" aria-label="Get connected with github (Opens in new window)" title="Get connected with github (Opens in new window)" href="https://github.com/golang"> <img src="/static/shared/logo/social/github.svg" /> </a> <a class="go-Header-socialIcon" aria-label="Get connected with twitter (Opens in new window)" title="Get connected with twitter (Opens in new window)" href="https://twitter.com/golang"> <img src="/static/shared/logo/social/twitter.svg" /> </a> <a class="go-Header-socialIcon" aria-label="Get connected with reddit (Opens in new window)" title="Get connected with reddit (Opens in new window)" href="https://www.reddit.com/r/golang/"> <img src="/static/shared/logo/social/reddit.svg" /> </a> <a class="go-Header-socialIcon" aria-label="Get connected with slack (Opens in new window)" title="Get connected with slack (Opens in new window)" href="https://invite.slack.golangbridge.org/"> <img src="/static/shared/logo/social/slack.svg" /> </a> <a class="go-Header-socialIcon" aria-label="Get connected with stack-overflow (Opens in new window)" title="" href="https://stackoverflow.com/collectives/go"> <img src="/static/shared/logo/social/stack-overflow.svg" /> </a> </div> </li> </ul> </li> </ul> <button class="go-Header-navOpen js-headerMenuButton go-Header-navOpen--white" data-gtmc="nav button" aria-label="Open navigation"> </button> </div> </nav> </div> </header> <aside class="go-NavigationDrawer js-header"> <nav class="go-NavigationDrawer-nav"> <div class="go-NavigationDrawer-header"> <a href="https://go.dev/"> <img class="go-NavigationDrawer-logo" src="/static/shared/logo/go-blue.svg" alt="Go."> </a> </div> <ul class="go-NavigationDrawer-list"> <li class="go-NavigationDrawer-listItem js-mobile-subnav-trigger go-NavigationDrawer-hasSubnav"> <a href="#"> <span>Why Go</span> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/navigate_next_gm_grey_24dp.svg" alt=""> </i> </a> <div class="go-NavigationDrawer go-NavigationDrawer-submenuItem"> <div class="go-NavigationDrawer-nav"> <div class="go-NavigationDrawer-header"> <a href="#"> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/navigate_before_gm_grey_24dp.svg" alt=""> </i> Why Go </a> </div> <ul class="go-NavigationDrawer-list"> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/solutions#case-studies"> Case Studies </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/solutions#use-cases"> Use Cases </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/security/"> Security </a> </li> </ul> </div> </div> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/learn/">Learn</a> </li> <li class="go-NavigationDrawer-listItem js-mobile-subnav-trigger go-NavigationDrawer-hasSubnav"> <a href="#"> <span>Docs</span> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/navigate_next_gm_grey_24dp.svg" alt=""> </i> </a> <div class="go-NavigationDrawer go-NavigationDrawer-submenuItem"> <div class="go-NavigationDrawer-nav"> <div class="go-NavigationDrawer-header"> <a href="#"><i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/navigate_before_gm_grey_24dp.svg" alt=""> </i> Docs </a> </div> <ul class="go-NavigationDrawer-list"> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/doc/effective_go"> Effective Go </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/doc/"> Go User Manual </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://pkg.go.dev/std"> Standard library </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/doc/devel/release"> Release Notes </a> </li> </ul> </div> </div> </li> <li class="go-NavigationDrawer-listItem go-NavigationDrawer-listItem--active"> <a href="/">Packages</a> </li> <li class="go-NavigationDrawer-listItem js-mobile-subnav-trigger go-NavigationDrawer-hasSubnav"> <a href="#"> <span>Community</span> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/navigate_next_gm_grey_24dp.svg" alt=""> </i> </a> <div class="go-NavigationDrawer go-NavigationDrawer-submenuItem"> <div class="go-NavigationDrawer-nav"> <div class="go-NavigationDrawer-header"> <a href="#"> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/navigate_before_gm_grey_24dp.svg" alt=""> </i> Community </a> </div> <ul class="go-NavigationDrawer-list"> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/talks/"> Recorded Talks </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://www.meetup.com/pro/go"> Meetups <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/launch_gm_grey_24dp.svg" alt=""> </i> </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://github.com/golang/go/wiki/Conferences"> Conferences <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/launch_gm_grey_24dp.svg" alt=""> </i> </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/blog"> Go blog </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/help"> Go project </a> </li> <li class="go-NavigationDrawer-listItem"> <div>Get connected</div> <div class="go-Header-socialIcons"> <a class="go-Header-socialIcon" href="https://groups.google.com/g/golang-nuts"><img src="/static/shared/logo/social/google-groups.svg" /></a> <a class="go-Header-socialIcon" href="https://github.com/golang"><img src="/static/shared/logo/social/github.svg" /></a> <a class="go-Header-socialIcon" href="https://twitter.com/golang"><img src="/static/shared/logo/social/twitter.svg" /></a> <a class="go-Header-socialIcon" href="https://www.reddit.com/r/golang/"><img src="/static/shared/logo/social/reddit.svg" /></a> <a class="go-Header-socialIcon" href="https://invite.slack.golangbridge.org/"><img src="/static/shared/logo/social/slack.svg" /></a> <a class="go-Header-socialIcon" href="https://stackoverflow.com/collectives/go"><img src="/static/shared/logo/social/stack-overflow.svg" /></a> </div> </li> </ul> </div> </div> </li> </ul> </nav> </aside> <div class="go-NavigationDrawer-scrim js-scrim" role="presentation"></div> <main class="go-Main" id="main-content"> <div class="go-Main-banner" role="alert"></div> <header class="go-Main-header js-mainHeader"> <nav class="go-Main-headerBreadcrumb go-Breadcrumb" aria-label="Breadcrumb" data-test-id="UnitHeader-breadcrumb"> <ol> <li data-test-id="UnitHeader-breadcrumbItem"> <a href="/" data-gtmc="breadcrumb link">Discover Packages</a> </li> <li data-test-id="UnitHeader-breadcrumbItem"> <a href="/std" data-gtmc="breadcrumb link">Standard library</a> </li> <li data-test-id="UnitHeader-breadcrumbItem"> <a href="/compress" data-gtmc="breadcrumb link">compress</a> </li> <li> <a href="/compress/flate@go1.24.1" data-gtmc="breadcrumb link" aria-current="location" data-test-id="UnitHeader-breadcrumbCurrent"> flate </a> <button class="go-Button go-Button--inline go-Clipboard js-clipboard" title="Copy path to clipboard.&#10;&#10;compress/flate" aria-label="Copy Path to Clipboard" data-to-copy="compress/flate" data-gtmc="breadcrumbs button" > <img class="go-Icon go-Icon--accented" height="24" width="24" src="/static/shared/icon/content_copy_gm_grey_24dp.svg" alt="" > </button> </li> </ol> </nav> <div class="go-Main-headerContent"> <div class="go-Main-headerTitle js-stickyHeader"> <a class="go-Main-headerLogo" href="https://go.dev/" aria-hidden="true" tabindex="-1" data-gtmc="header link" aria-label="Link to Go Homepage"> <img height="78" width="207" src="/static/shared/logo/go-blue.svg" alt="Go"> </a> <h1 class="UnitHeader-titleHeading" data-test-id="UnitHeader-title">flate</h1> <span class="go-Chip go-Chip--inverted">package</span> <span class="go-Chip go-Chip--inverted">standard library</span> <button class="go-Button go-Button--inline go-Clipboard js-clipboard" title="Copy path to clipboard.&#10;&#10;compress/flate" aria-label="Copy Path to Clipboard" data-to-copy="compress/flate" data-gtmc="title button" tabindex="-1" > <img class="go-Icon go-Icon--accented" height="24" width="24" src="/static/shared/icon/content_copy_gm_grey_24dp.svg" alt="" /> </button> </div> <div class="go-Main-headerDetails"> <span class="go-Main-headerDetailItem" data-test-id="UnitHeader-version"> <a href="?tab=versions" aria-label="Version: go1.24.1" data-gtmc="header link" aria-describedby="version-description"> <span class="go-textSubtle" aria-hidden="true">Version: </span> go1.24.1 </a> <div class="screen-reader-only" id="version-description" hidden> Opens a new window with list of versions in this module. </div> <span class="DetailsHeader-badge--latest" data-test-id="UnitHeader-minorVersionBanner"> <span class="go-Chip DetailsHeader-span--latest">Latest</span> <span class="go-Chip DetailsHeader-span--notAtLatest"> Latest <details class="go-Tooltip js-tooltip" data-gtmc="tooltip"> <summary> <img class="go-Icon go-Icon--inverted" height="24" width="24" src="/static/shared/icon/alert_gm_grey_24dp.svg" alt="Warning"> </summary> <p>This package is not in the latest version of its module.</p> </details> </span> <a href="/compress/flate" aria-label="Go to Latest Version" data-gtmc="header link"> <span class="go-Chip go-Chip--alert DetailsHeader-span--goToLatest">Go to latest</span> </a> </span> </span> <span class="go-Main-headerDetailItem" data-test-id="UnitHeader-commitTime"> Published: Mar 4, 2025 </span> <span class="go-Main-headerDetailItem" data-test-id="UnitHeader-licenses"> License: <a href="/compress/flate?tab=licenses" data-test-id="UnitHeader-license" data-gtmc="header link" aria-describedby="license-description">BSD-3-Clause</a> </span> <div class="screen-reader-only" id="license-description" hidden> Opens a new window with license information. </div> <span class="go-Main-headerDetailItem" data-test-id="UnitHeader-imports"> <a href="/compress/flate?tab=imports" aria-label="Imports: 9" data-gtmc="header link" aria-describedby="imports-description"> <span class="go-textSubtle">Imports: </span>9 </a> </span> <div class="screen-reader-only" id="imports-description" hidden> Opens a new window with list of imports. </div> <span class="go-Main-headerDetailItem" data-test-id="UnitHeader-importedby"> <a href="/compress/flate?tab=importedby" aria-label="Imported By: 7,463" data-gtmc="header link" aria-describedby="importedby-description"> <span class="go-textSubtle">Imported by: </span>7,463 </a> </span> <div class="screen-reader-only" id="importedby-description" hidden> Opens a new window with list of known importers. </div> </div> <div class="UnitHeader-overflowContainer"> <svg class="UnitHeader-overflowImage" xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"> <path d="M0 0h24v24H0z" fill="none"/> <path d="M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"/> </svg> <select class="UnitHeader-overflowSelect js-selectNav" tabindex="-1"> <option value="/">Main</option> <option value="/compress/flate?tab=versions"> Versions </option> <option value="/compress/flate?tab=licenses"> Licenses </option> <option value="/compress/flate?tab=imports"> Imports </option> <option value="/compress/flate?tab=importedby"> Imported By </option> </select> </div> </div> </header> <aside class="go-Main-aside js-mainAside"> <div class="UnitMeta"> <h2 class="go-textLabel">Details</h2> <ul class="UnitMeta-details"> <li> <details class="go-Tooltip js-tooltip" data-gtmc="tooltip"> <summary class="go-textSubtle"> <img class="go-Icon go-Icon--accented" tabindex="0" role="button"src="/static/shared/icon/check_circle_gm_grey_24dp.svg" alt="checked" aria-label="Valid file, toggle tooltip"height="24" width="24"> Valid <a href="https://cs.opensource.google/go/go/+/go1.24.1:src/go.mod" target="_blank" rel="noopener">go.mod</a> file <img class="go-Icon" role="button" tabindex="0" src="/static/shared/icon/help_gm_grey_24dp.svg" alt="" aria-label="Toggle go.mod validity tooltip" height="24" width="24"> </summary> <p aria-live="polite" role="tooltip"> The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go. </p> </details> </li> <li> <details class="go-Tooltip js-tooltip" data-gtmc="tooltip"> <summary class="go-textSubtle"> <img class="go-Icon go-Icon--accented" tabindex="0" role="button"src="/static/shared/icon/check_circle_gm_grey_24dp.svg" alt="checked" aria-label="Valid file, toggle tooltip"height="24" width="24"> Redistributable license <img class="go-Icon" role="button" tabindex="0" src="/static/shared/icon/help_gm_grey_24dp.svg" alt="" aria-label="Toggle redistributable help tooltip" height="24" width="24"> </summary> <p aria-live="polite" role="tooltip"> Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed. </p> </details> </li> <li> <details class="go-Tooltip js-tooltip" data-gtmc="tooltip"> <summary class="go-textSubtle"> <img class="go-Icon go-Icon--accented" tabindex="0" role="button"src="/static/shared/icon/check_circle_gm_grey_24dp.svg" alt="checked" aria-label="Valid file, toggle tooltip"height="24" width="24"> Tagged version <img class="go-Icon" role="button" tabindex="0" src="/static/shared/icon/help_gm_grey_24dp.svg" alt="" aria-label="Toggle tagged version tooltip" height="24" width="24"> </summary> <p aria-live="polite" role="tooltip">Modules with tagged versions give importers more predictable builds.</p> </details> </li> <li> <details class="go-Tooltip js-tooltip" data-gtmc="tooltip"> <summary class="go-textSubtle"> <img class="go-Icon go-Icon--accented" tabindex="0" role="button"src="/static/shared/icon/check_circle_gm_grey_24dp.svg" alt="checked" aria-label="Valid file, toggle tooltip"height="24" width="24"> Stable version <img class="go-Icon" role="button" tabindex="0" aria-label="Toggle stable version tooltip" src="/static/shared/icon/help_gm_grey_24dp.svg" alt="" height="24" width="24"> </summary> <p aria-live="polite" role="tooltip">When a project reaches major version v1 it is considered stable.</p> </details> </li> <li class="UnitMeta-detailsLearn"> <a href="/about#best-practices" data-gtmc="meta link">Learn more about best practices</a> </li> </ul> <h2 class="go-textLabel">Repository</h2> <div class="UnitMeta-repo"> <a href="https://cs.opensource.google/go/go" title="https://cs.opensource.google/go/go" target="_blank" rel="noopener"> cs.opensource.google/go/go </a> </div> <h2 class="go-textLabel" data-test-id="links-heading">Links</h2> <ul class="UnitMeta-links"> <li> <a href="https://go.dev/security/policy" title="Report security issues in the Go standard library and sub-repositories"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/security_grey_24dp.svg" alt=""> Report a Vulnerability </a> </li> </ul> </div> </aside> <nav class="go-Main-nav go-Main-nav--sticky js-mainNav" aria-label="Outline"> <div class="go-Main-navDesktop"> <div class="UnitOutline-jumpTo"> <button class="UnitOutline-jumpToInput go-ShortcutKey js-jumpToInput" aria-controls="jump-to-modal" aria-label="Open Jump to Identifier" data-shortcut="f" data-shortcut-alt="find" data-test-id="jump-to-button" data-gtmc="outline button"> Jump to ... </button> </div> <ul class="go-Tree js-tree" role="tree" aria-label="Outline"> <li> <a href="#section-documentation" data-gtmc="outline link"> Documentation </a> <ul> <li> <a href="#pkg-overview" data-gtmc="doc outline link">Overview</a> </li> <li class="DocNav-overview"> <a href="#pkg-index" data-gtmc="doc outline link"> Index </a> <ul> <li> <a href="#pkg-examples" data-gtmc="doc outline link"> Examples </a> </li> </ul> </li> <li class="DocNav-constants"> <a href="#pkg-constants" data-gtmc="doc outline link"> Constants </a> </li> <li class="DocNav-variables"> <a href="#pkg-variables" data-gtmc="doc outline link"> Variables </a> </li> <li class="DocNav-functions"> <a href="#pkg-functions" data-gtmc="doc outline link"> Functions </a> <ul> <li> <a href="#NewReader" title="NewReader(r)" data-gtmc="doc outline link"> NewReader(r) </a> </li> <li> <a href="#NewReaderDict" title="NewReaderDict(r, dict)" data-gtmc="doc outline link"> NewReaderDict(r, dict) </a> </li> </ul> </li> <li class="DocNav-types"> <a href="#pkg-types" data-gtmc="doc outline link"> Types </a> <ul> <li> <a href="#CorruptInputError" title="type CorruptInputError" data-gtmc="doc outline link"> type CorruptInputError </a> <ul> <li> <a href="#CorruptInputError.Error" title="(e) Error()" data-gtmc="doc outline link"> (e) Error() </a> </li> </ul> </li> <li> <a href="#InternalError" title="type InternalError" data-gtmc="doc outline link"> type InternalError </a> <ul> <li> <a href="#InternalError.Error" title="(e) Error()" data-gtmc="doc outline link"> (e) Error() </a> </li> </ul> </li> <li> <a href="#ReadError" title="type ReadError" data-gtmc="doc outline link"> type ReadError </a> <ul> <li> <a href="#ReadError.Error" title="(e) Error()" data-gtmc="doc outline link"> (e) Error() </a> </li> </ul> </li> <li> <a href="#Reader" title="type Reader" data-gtmc="doc outline link"> type Reader </a> </li> <li> <a href="#Resetter" title="type Resetter" data-gtmc="doc outline link"> type Resetter </a> </li> <li> <a href="#WriteError" title="type WriteError" data-gtmc="doc outline link"> type WriteError </a> <ul> <li> <a href="#WriteError.Error" title="(e) Error()" data-gtmc="doc outline link"> (e) Error() </a> </li> </ul> </li> <li> <a href="#Writer" title="type Writer" data-gtmc="doc outline link"> type Writer </a> <ul> <li> <a href="#NewWriter" title="NewWriter(w, level)" data-gtmc="doc outline link"> NewWriter(w, level) </a> </li> <li> <a href="#NewWriterDict" title="NewWriterDict(w, level, dict)" data-gtmc="doc outline link"> NewWriterDict(w, level, dict) </a> </li> <li> <a href="#Writer.Close" title="(w) Close()" data-gtmc="doc outline link"> (w) Close() </a> </li> <li> <a href="#Writer.Flush" title="(w) Flush()" data-gtmc="doc outline link"> (w) Flush() </a> </li> <li> <a href="#Writer.Reset" title="(w) Reset(dst)" data-gtmc="doc outline link"> (w) Reset(dst) </a> </li> <li> <a href="#Writer.Write" title="(w) Write(data)" data-gtmc="doc outline link"> (w) Write(data) </a> </li> </ul> </li> </ul> </li> </ul> </li> <li> <a href="#section-sourcefiles" data-gtmc="outline link"> Source Files </a> </li> </ul> </div> <div class="go-Main-navMobile js-mainNavMobile"> <label class="go-Label"> <select class="go-Select"> <option selected disabled>Documentation</option> </select> </label> </div> </nav> <article class="go-Main-article js-mainContent"> <div class="UnitDetails" data-test-id="UnitDetails" style="display: block;"> <div class="UnitDetails-content js-unitDetailsContent" data-test-id="UnitDetails-content"> <div class="UnitDoc"> <h2 class="UnitDoc-title" id="section-documentation"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/code_gm_grey_24dp.svg" alt=""> Documentation <a class="UnitDoc-idLink" href="#section-documentation" title="Go to Documentation" aria-label="Go to Documentation">露</a> </h2> <div class="Documentation js-documentation"> <div class="Documentation-content js-docContent"> <section class="Documentation-overview"> <h3 tabindex="-1" id="pkg-overview" class="Documentation-overviewHeader">Overview <a href="#pkg-overview" title="Go to Overview" aria-label="Go to Overview">露</a></h3> <p>Package flate implements the DEFLATE compressed data format, described in <a href="https://rfc-editor.org/rfc/rfc1951.html">RFC 1951</a>. The gzip and zlib packages implement access to DEFLATE-based file formats. </p> <details tabindex="-1" id="example-package-Dictionary" class="Documentation-exampleDetails js-exampleContainer"> <summary class="Documentation-exampleDetailsHeader">Example (Dictionary) <a href="#example-package-Dictionary" title="Go to Example (Dictionary)" aria-label="Go to Example (Dictionary)">露</a></summary> <div class="Documentation-exampleDetailsBody"> <p>A preset dictionary can be used to improve the compression ratio. The downside to using a dictionary is that the compressor and decompressor must agree in advance what dictionary to use. </p> <pre class="Documentation-exampleCode"> package main import ( &#34;bytes&#34; &#34;compress/flate&#34; &#34;fmt&#34; &#34;io&#34; &#34;log&#34; &#34;os&#34; &#34;strings&#34; ) func main() { // The dictionary is a string of bytes. When compressing some input data, // the compressor will attempt to substitute substrings with matches found // in the dictionary. As such, the dictionary should only contain substrings // that are expected to be found in the actual data stream. const dict = `&lt;?xml version=&#34;1.0&#34;?&gt;` + `&lt;book&gt;` + `&lt;data&gt;` + `&lt;meta name=&#34;` + `&#34; content=&#34;` // The data to compress should (but is not required to) contain frequent // substrings that match those in the dictionary. const data = `&lt;?xml version=&#34;1.0&#34;?&gt; &lt;book&gt; &lt;meta name=&#34;title&#34; content=&#34;The Go Programming Language&#34;/&gt; &lt;meta name=&#34;authors&#34; content=&#34;Alan Donovan and Brian Kernighan&#34;/&gt; &lt;meta name=&#34;published&#34; content=&#34;2015-10-26&#34;/&gt; &lt;meta name=&#34;isbn&#34; content=&#34;978-0134190440&#34;/&gt; &lt;data&gt;...&lt;/data&gt; &lt;/book&gt; ` var b bytes.Buffer // Compress the data using the specially crafted dictionary. zw, err := flate.NewWriterDict(&amp;b, flate.DefaultCompression, []byte(dict)) if err != nil { log.Fatal(err) } if _, err := io.Copy(zw, strings.NewReader(data)); err != nil { log.Fatal(err) } if err := zw.Close(); err != nil { log.Fatal(err) } // The decompressor must use the same dictionary as the compressor. // Otherwise, the input may appear as corrupted. fmt.Println(&#34;Decompressed output using the dictionary:&#34;) zr := flate.NewReaderDict(bytes.NewReader(b.Bytes()), []byte(dict)) if _, err := io.Copy(os.Stdout, zr); err != nil { log.Fatal(err) } if err := zr.Close(); err != nil { log.Fatal(err) } fmt.Println() // Substitute all of the bytes in the dictionary with a &#39;#&#39; to visually // demonstrate the approximate effectiveness of using a preset dictionary. fmt.Println(&#34;Substrings matched by the dictionary are marked with #:&#34;) hashDict := []byte(dict) for i := range hashDict { hashDict[i] = &#39;#&#39; } zr = flate.NewReaderDict(&amp;b, hashDict) if _, err := io.Copy(os.Stdout, zr); err != nil { log.Fatal(err) } if err := zr.Close(); err != nil { log.Fatal(err) } } </pre> <pre><span class="Documentation-exampleOutputLabel">Output:</span> <span class="Documentation-exampleOutput">Decompressed output using the dictionary: &lt;?xml version=&#34;1.0&#34;?&gt; &lt;book&gt; &lt;meta name=&#34;title&#34; content=&#34;The Go Programming Language&#34;/&gt; &lt;meta name=&#34;authors&#34; content=&#34;Alan Donovan and Brian Kernighan&#34;/&gt; &lt;meta name=&#34;published&#34; content=&#34;2015-10-26&#34;/&gt; &lt;meta name=&#34;isbn&#34; content=&#34;978-0134190440&#34;/&gt; &lt;data&gt;...&lt;/data&gt; &lt;/book&gt; Substrings matched by the dictionary are marked with #: ##################### ###### ############title###########The Go Programming Language&#34;/# ############authors###########Alan Donovan and Brian Kernighan&#34;/# ############published###########2015-10-26&#34;/# ############isbn###########978-0134190440&#34;/# ######...&lt;/##### &lt;/##### </span></pre> </div> <div class="Documentation-exampleButtonsContainer"> <p class="Documentation-exampleError" role="alert" aria-atomic="true"></p> <button class="Documentation-exampleShareButton" aria-label="Share Code">Share</button> <button class="Documentation-exampleFormatButton" aria-label="Format Code">Format</button> <button class="Documentation-exampleRunButton" aria-label="Run Code">Run</button> </div></details> <details tabindex="-1" id="example-package-Reset" class="Documentation-exampleDetails js-exampleContainer"> <summary class="Documentation-exampleDetailsHeader">Example (Reset) <a href="#example-package-Reset" title="Go to Example (Reset)" aria-label="Go to Example (Reset)">露</a></summary> <div class="Documentation-exampleDetailsBody"> <p>In performance critical applications, Reset can be used to discard the current compressor or decompressor state and reinitialize them quickly by taking advantage of previously allocated memory. </p> <pre class="Documentation-exampleCode"> package main import ( &#34;bytes&#34; &#34;compress/flate&#34; &#34;io&#34; &#34;log&#34; &#34;os&#34; &#34;strings&#34; ) func main() { proverbs := []string{ &#34;Don&#39;t communicate by sharing memory, share memory by communicating.\n&#34;, &#34;Concurrency is not parallelism.\n&#34;, &#34;The bigger the interface, the weaker the abstraction.\n&#34;, &#34;Documentation is for users.\n&#34;, } var r strings.Reader var b bytes.Buffer buf := make([]byte, 32&lt;&lt;10) zw, err := flate.NewWriter(nil, flate.DefaultCompression) if err != nil { log.Fatal(err) } zr := flate.NewReader(nil) for _, s := range proverbs { r.Reset(s) b.Reset() // Reset the compressor and encode from some input stream. zw.Reset(&amp;b) if _, err := io.CopyBuffer(zw, &amp;r, buf); err != nil { log.Fatal(err) } if err := zw.Close(); err != nil { log.Fatal(err) } // Reset the decompressor and decode to some output stream. if err := zr.(flate.Resetter).Reset(&amp;b, nil); err != nil { log.Fatal(err) } if _, err := io.CopyBuffer(os.Stdout, zr, buf); err != nil { log.Fatal(err) } if err := zr.Close(); err != nil { log.Fatal(err) } } } </pre> <pre><span class="Documentation-exampleOutputLabel">Output:</span> <span class="Documentation-exampleOutput">Don&#39;t communicate by sharing memory, share memory by communicating. Concurrency is not parallelism. The bigger the interface, the weaker the abstraction. Documentation is for users. </span></pre> </div> <div class="Documentation-exampleButtonsContainer"> <p class="Documentation-exampleError" role="alert" aria-atomic="true"></p> <button class="Documentation-exampleShareButton" aria-label="Share Code">Share</button> <button class="Documentation-exampleFormatButton" aria-label="Format Code">Format</button> <button class="Documentation-exampleRunButton" aria-label="Run Code">Run</button> </div></details> <details tabindex="-1" id="example-package-Synchronization" class="Documentation-exampleDetails js-exampleContainer"> <summary class="Documentation-exampleDetailsHeader">Example (Synchronization) <a href="#example-package-Synchronization" title="Go to Example (Synchronization)" aria-label="Go to Example (Synchronization)">露</a></summary> <div class="Documentation-exampleDetailsBody"> <p>DEFLATE is suitable for transmitting compressed data across the network. </p> <pre class="Documentation-exampleCode"> package main import ( &#34;compress/flate&#34; &#34;fmt&#34; &#34;io&#34; &#34;log&#34; &#34;strings&#34; &#34;sync&#34; ) func main() { var wg sync.WaitGroup defer wg.Wait() // Use io.Pipe to simulate a network connection. // A real network application should take care to properly close the // underlying connection. rp, wp := io.Pipe() // Start a goroutine to act as the transmitter. wg.Add(1) go func() { defer wg.Done() zw, err := flate.NewWriter(wp, flate.BestSpeed) if err != nil { log.Fatal(err) } b := make([]byte, 256) for _, m := range strings.Fields(&#34;A long time ago in a galaxy far, far away...&#34;) { // We use a simple framing format where the first byte is the // message length, followed the message itself. b[0] = uint8(copy(b[1:], m)) if _, err := zw.Write(b[:1+len(m)]); err != nil { log.Fatal(err) } // Flush ensures that the receiver can read all data sent so far. if err := zw.Flush(); err != nil { log.Fatal(err) } } if err := zw.Close(); err != nil { log.Fatal(err) } }() // Start a goroutine to act as the receiver. wg.Add(1) go func() { defer wg.Done() zr := flate.NewReader(rp) b := make([]byte, 256) for { // Read the message length. // This is guaranteed to return for every corresponding // Flush and Close on the transmitter side. if _, err := io.ReadFull(zr, b[:1]); err != nil { if err == io.EOF { break // The transmitter closed the stream } log.Fatal(err) } // Read the message content. n := int(b[0]) if _, err := io.ReadFull(zr, b[:n]); err != nil { log.Fatal(err) } fmt.Printf(&#34;Received %d bytes: %s\n&#34;, n, b[:n]) } fmt.Println() if err := zr.Close(); err != nil { log.Fatal(err) } }() } </pre> <pre><span class="Documentation-exampleOutputLabel">Output:</span> <span class="Documentation-exampleOutput">Received 1 bytes: A Received 4 bytes: long Received 4 bytes: time Received 3 bytes: ago Received 2 bytes: in Received 1 bytes: a Received 6 bytes: galaxy Received 4 bytes: far, Received 3 bytes: far Received 7 bytes: away... </span></pre> </div> <div class="Documentation-exampleButtonsContainer"> <p class="Documentation-exampleError" role="alert" aria-atomic="true"></p> <button class="Documentation-exampleShareButton" aria-label="Share Code">Share</button> <button class="Documentation-exampleFormatButton" aria-label="Format Code">Format</button> <button class="Documentation-exampleRunButton" aria-label="Run Code">Run</button> </div></details> </section><section class="Documentation-index"> <h3 id="pkg-index" class="Documentation-indexHeader">Index <a href="#pkg-index" title="Go to Index" aria-label="Go to Index">露</a></h3> <ul class="Documentation-indexList"> <li class="Documentation-indexConstants"><a href="#pkg-constants">Constants</a></li> <li class="Documentation-indexFunction"> <a href="#NewReader">func NewReader(r io.Reader) io.ReadCloser</a></li> <li class="Documentation-indexFunction"> <a href="#NewReaderDict">func NewReaderDict(r io.Reader, dict []byte) io.ReadCloser</a></li> <li class="Documentation-indexType"> <a href="#CorruptInputError">type CorruptInputError</a></li> <li><ul class="Documentation-indexTypeMethods"> <li> <a href="#CorruptInputError.Error">func (e CorruptInputError) Error() string</a></li> </ul></li> <li class="Documentation-indexType"> <a href="#InternalError">type InternalError</a></li> <li><ul class="Documentation-indexTypeMethods"> <li> <a href="#InternalError.Error">func (e InternalError) Error() string</a></li> </ul></li> <li class="Documentation-indexType"> <a class="js-deprecatedTagLink" href="#ReadError">type ReadError</a><span class="Documentation-indexDeprecated Documentation-deprecatedTag">deprecated</span></li> <li><ul class="Documentation-indexTypeMethods"> <li> <a href="#ReadError.Error">func (e *ReadError) Error() string</a></li> </ul></li> <li class="Documentation-indexType"> <a href="#Reader">type Reader</a></li> <li class="Documentation-indexType"> <a href="#Resetter">type Resetter</a></li> <li class="Documentation-indexType"> <a class="js-deprecatedTagLink" href="#WriteError">type WriteError</a><span class="Documentation-indexDeprecated Documentation-deprecatedTag">deprecated</span></li> <li><ul class="Documentation-indexTypeMethods"> <li> <a href="#WriteError.Error">func (e *WriteError) Error() string</a></li> </ul></li> <li class="Documentation-indexType"> <a href="#Writer">type Writer</a></li> <li><ul class="Documentation-indexTypeFunctions"> <li> <a href="#NewWriter">func NewWriter(w io.Writer, level int) (*Writer, error)</a></li> <li> <a href="#NewWriterDict">func NewWriterDict(w io.Writer, level int, dict []byte) (*Writer, error)</a></li> </ul></li> <li><ul class="Documentation-indexTypeMethods"> <li> <a href="#Writer.Close">func (w *Writer) Close() error</a></li> <li> <a href="#Writer.Flush">func (w *Writer) Flush() error</a></li> <li> <a href="#Writer.Reset">func (w *Writer) Reset(dst io.Writer)</a></li> <li> <a href="#Writer.Write">func (w *Writer) Write(data []byte) (n int, err error)</a></li> </ul></li> </ul> </section><section class="Documentation-examples"> <h4 tabindex="-1" id="pkg-examples" class="Documentation-examplesHeader">Examples <a class="Documentation-idLink" href="#pkg-examples" title="Go to Examples" aria-label="Go to Examples">露</a></h4> <ul class="Documentation-examplesList"> <li><a href="#example-package-Dictionary" class="js-exampleHref">Package (Dictionary)</a></li> <li><a href="#example-package-Reset" class="js-exampleHref">Package (Reset)</a></li> <li><a href="#example-package-Synchronization" class="js-exampleHref">Package (Synchronization)</a></li> </ul> </section><h3 tabindex="-1" id="pkg-constants" class="Documentation-constantsHeader">Constants <a href="#pkg-constants" title="Go to Constants" aria-label="Go to Constants">露</a></h3> <section class="Documentation-constants"> <div class="Documentation-declaration"> <span class="Documentation-declarationLink"><a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/deflate.go;l=14">View Source</a></span> <pre>const ( <span id="NoCompression" data-kind="constant"> NoCompression = 0 </span><span id="BestSpeed" data-kind="constant"> BestSpeed = 1 </span><span id="BestCompression" data-kind="constant"> BestCompression = 9 </span><span id="DefaultCompression" data-kind="constant"> DefaultCompression = -1 </span> <span id="HuffmanOnly" data-kind="constant"> <span class="comment">// HuffmanOnly disables Lempel-Ziv match searching and only performs Huffman</span> </span> <span class="comment">// entropy encoding. This mode is useful in compressing data that has</span> <span class="comment">// already been compressed with an LZ style algorithm (e.g. Snappy or LZ4)</span> <span class="comment">// that lacks an entropy encoder. Compression gains are achieved when</span> <span class="comment">// certain bytes in the input stream occur more frequently than others.</span> <span class="comment">//</span> <span class="comment">// Note that HuffmanOnly produces a compressed output that is</span> <span class="comment">// <a href="https://rfc-editor.org/rfc/rfc1951.html">RFC 1951</a> compliant. That is, any valid DEFLATE decompressor will</span> <span class="comment">// continue to be able to decompress this output.</span> HuffmanOnly = -2 )</pre> </div> </section> <h3 tabindex="-1" id="pkg-variables" class="Documentation-variablesHeader">Variables <a href="#pkg-variables" title="Go to Variables" aria-label="Go to Variables">露</a></h3> <section class="Documentation-variables"><p class="Documentation-empty">This section is empty.</p></section> <h3 tabindex="-1" id="pkg-functions" class="Documentation-functionsHeader">Functions <a href="#pkg-functions" title="Go to Functions" aria-label="Go to Functions">露</a></h3> <section class="Documentation-functions"><div class="Documentation-function"> <h4 tabindex="-1" id="NewReader" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/inflate.go;l=807">NewReader</a> <a class="Documentation-idLink" href="#NewReader" title="Go to NewReader" aria-label="Go to NewReader">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func NewReader(r <a href="/io">io</a>.<a href="/io#Reader">Reader</a>) <a href="/io">io</a>.<a href="/io#ReadCloser">ReadCloser</a></pre> </div> <p>NewReader returns a new ReadCloser that can be used to read the uncompressed version of r. If r does not also implement <a href="/io#ByteReader">io.ByteReader</a>, the decompressor may read more data than necessary from r. The reader returns <a href="/io#EOF">io.EOF</a> after the final block in the DEFLATE stream has been encountered. Any trailing data after the final block is ignored. </p><p>The <a href="/io#ReadCloser">io.ReadCloser</a> returned by NewReader also implements <a href="#Resetter">Resetter</a>. </p> </div><div class="Documentation-function"> <h4 tabindex="-1" id="NewReaderDict" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/inflate.go;l=826">NewReaderDict</a> <a class="Documentation-idLink" href="#NewReaderDict" title="Go to NewReaderDict" aria-label="Go to NewReaderDict">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func NewReaderDict(r <a href="/io">io</a>.<a href="/io#Reader">Reader</a>, dict []<a href="/builtin#byte">byte</a>) <a href="/io">io</a>.<a href="/io#ReadCloser">ReadCloser</a></pre> </div> <p>NewReaderDict is like <a href="#NewReader">NewReader</a> but initializes the reader with a preset dictionary. The returned <a href="#Reader">Reader</a> behaves as if the uncompressed data stream started with the given dictionary, which has already been read. NewReaderDict is typically used to read data compressed by NewWriterDict. </p><p>The ReadCloser returned by NewReaderDict also implements <a href="#Resetter">Resetter</a>. </p> </div></section> <h3 tabindex="-1" id="pkg-types" class="Documentation-typesHeader">Types <a href="#pkg-types" title="Go to Types" aria-label="Go to Types">露</a></h3> <section class="Documentation-types"><div class="Documentation-type"> <h4 tabindex="-1" id="CorruptInputError" data-kind="type" class="Documentation-typeHeader"> <span>type <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/inflate.go;l=33">CorruptInputError</a> <a class="Documentation-idLink" href="#CorruptInputError" title="Go to CorruptInputError" aria-label="Go to CorruptInputError">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>type CorruptInputError <a href="/builtin#int64">int64</a></pre> </div> <p>A CorruptInputError reports the presence of corrupt input at a given offset. </p> <div class="Documentation-typeMethod"> <h4 tabindex="-1" id="CorruptInputError.Error" data-kind="method" class="Documentation-typeMethodHeader"> <span>func (CorruptInputError) <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/inflate.go;l=35">Error</a> <a class="Documentation-idLink" href="#CorruptInputError.Error" title="Go to CorruptInputError.Error" aria-label="Go to CorruptInputError.Error">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func (e <a href="#CorruptInputError">CorruptInputError</a>) Error() <a href="/builtin#string">string</a></pre> </div> </div> </div><div class="Documentation-type"> <h4 tabindex="-1" id="InternalError" data-kind="type" class="Documentation-typeHeader"> <span>type <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/inflate.go;l=40">InternalError</a> <a class="Documentation-idLink" href="#InternalError" title="Go to InternalError" aria-label="Go to InternalError">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>type InternalError <a href="/builtin#string">string</a></pre> </div> <p>An InternalError reports an error in the flate code itself. </p> <div class="Documentation-typeMethod"> <h4 tabindex="-1" id="InternalError.Error" data-kind="method" class="Documentation-typeMethodHeader"> <span>func (InternalError) <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/inflate.go;l=42">Error</a> <a class="Documentation-idLink" href="#InternalError.Error" title="Go to InternalError.Error" aria-label="Go to InternalError.Error">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func (e <a href="#InternalError">InternalError</a>) Error() <a href="/builtin#string">string</a></pre> </div> </div> </div><div class="Documentation-type"> <details class="Documentation-deprecatedDetails js-deprecatedDetails"> <summary> <h4 tabindex="-1" id="ReadError" data-kind="type" class="Documentation-typeHeader"> <span class="Documentation-deprecatedTitle"> type <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/inflate.go;l=47">ReadError</a> <span class="Documentation-deprecatedTag">deprecated</span> <span class="Documentation-deprecatedBody"></span> </span> <span class="Documentation-sinceVersion"> </span> </h4> </summary> <div class="go-Message go-Message--warning Documentation-deprecatedItemBody"> <div class="Documentation-declaration"> <pre>type ReadError struct { <span id="ReadError.Offset" data-kind="field"> Offset <a href="/builtin#int64">int64</a> <span class="comment">// byte offset where error occurred</span> </span><span id="ReadError.Err" data-kind="field"> Err <a href="/builtin#error">error</a> <span class="comment">// error returned by underlying Read</span> </span>}</pre> </div> <p>A ReadError reports an error encountered while reading input. </p><p>Deprecated: No longer returned. </p> <div class="Documentation-typeMethod"> <h4 tabindex="-1" id="ReadError.Error" data-kind="method" class="Documentation-typeMethodHeader"> <span>func (*ReadError) <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/inflate.go;l=52">Error</a> <a class="Documentation-idLink" href="#ReadError.Error" title="Go to ReadError.Error" aria-label="Go to ReadError.Error">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func (e *<a href="#ReadError">ReadError</a>) Error() <a href="/builtin#string">string</a></pre> </div> </div> </div> </details> </div><div class="Documentation-type"> <h4 tabindex="-1" id="Reader" data-kind="type" class="Documentation-typeHeader"> <span>type <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/inflate.go;l=261">Reader</a> <a class="Documentation-idLink" href="#Reader" title="Go to Reader" aria-label="Go to Reader">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>type Reader interface { <a href="/io">io</a>.<a href="/io#Reader">Reader</a> <a href="/io">io</a>.<a href="/io#ByteReader">ByteReader</a> }</pre> </div> <p>The actual read interface needed by <a href="#NewReader">NewReader</a>. If the passed in io.Reader does not also have ReadByte, the <a href="#NewReader">NewReader</a> will introduce its own buffering. </p> </div><div class="Documentation-type"> <h4 tabindex="-1" id="Resetter" data-kind="type" class="Documentation-typeHeader"> <span>type <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/inflate.go;l=71">Resetter</a> <a class="Documentation-idLink" href="#Resetter" title="Go to Resetter" aria-label="Go to Resetter">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.4</span> </span> </h4> <div class="Documentation-declaration"> <pre>type Resetter interface { <span id="Resetter.Reset" data-kind="method"> <span class="comment">// Reset discards any buffered data and resets the Resetter as if it was</span> </span> <span class="comment">// newly initialized with the given reader.</span> Reset(r <a href="/io">io</a>.<a href="/io#Reader">Reader</a>, dict []<a href="/builtin#byte">byte</a>) <a href="/builtin#error">error</a> }</pre> </div> <p>Resetter resets a ReadCloser returned by <a href="#NewReader">NewReader</a> or <a href="#NewReaderDict">NewReaderDict</a> to switch to a new underlying <a href="#Reader">Reader</a>. This permits reusing a ReadCloser instead of allocating a new one. </p> </div><div class="Documentation-type"> <details class="Documentation-deprecatedDetails js-deprecatedDetails"> <summary> <h4 tabindex="-1" id="WriteError" data-kind="type" class="Documentation-typeHeader"> <span class="Documentation-deprecatedTitle"> type <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/inflate.go;l=59">WriteError</a> <span class="Documentation-deprecatedTag">deprecated</span> <span class="Documentation-deprecatedBody"></span> </span> <span class="Documentation-sinceVersion"> </span> </h4> </summary> <div class="go-Message go-Message--warning Documentation-deprecatedItemBody"> <div class="Documentation-declaration"> <pre>type WriteError struct { <span id="WriteError.Offset" data-kind="field"> Offset <a href="/builtin#int64">int64</a> <span class="comment">// byte offset where error occurred</span> </span><span id="WriteError.Err" data-kind="field"> Err <a href="/builtin#error">error</a> <span class="comment">// error returned by underlying Write</span> </span>}</pre> </div> <p>A WriteError reports an error encountered while writing output. </p><p>Deprecated: No longer returned. </p> <div class="Documentation-typeMethod"> <h4 tabindex="-1" id="WriteError.Error" data-kind="method" class="Documentation-typeMethodHeader"> <span>func (*WriteError) <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/inflate.go;l=64">Error</a> <a class="Documentation-idLink" href="#WriteError.Error" title="Go to WriteError.Error" aria-label="Go to WriteError.Error">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func (e *<a href="#WriteError">WriteError</a>) Error() <a href="/builtin#string">string</a></pre> </div> </div> </div> </details> </div><div class="Documentation-type"> <h4 tabindex="-1" id="Writer" data-kind="type" class="Documentation-typeHeader"> <span>type <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/deflate.go;l=699">Writer</a> <a class="Documentation-idLink" href="#Writer" title="Go to Writer" aria-label="Go to Writer">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>type Writer struct { <span class="comment">// contains filtered or unexported fields</span> }</pre> </div> <p>A Writer takes data written to it and writes the compressed form of that data to an underlying writer (see <a href="#NewWriter">NewWriter</a>). </p> <div class="Documentation-typeFunc"> <h4 tabindex="-1" id="NewWriter" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/deflate.go;l=662">NewWriter</a> <a class="Documentation-idLink" href="#NewWriter" title="Go to NewWriter" aria-label="Go to NewWriter">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func NewWriter(w <a href="/io">io</a>.<a href="/io#Writer">Writer</a>, level <a href="/builtin#int">int</a>) (*<a href="#Writer">Writer</a>, <a href="/builtin#error">error</a>)</pre> </div> <p>NewWriter returns a new <a href="#Writer">Writer</a> compressing data at the given level. Following zlib, levels range from 1 (<a href="#BestSpeed">BestSpeed</a>) to 9 (<a href="#BestCompression">BestCompression</a>); higher levels typically run slower but compress more. Level 0 (<a href="#NoCompression">NoCompression</a>) does not attempt any compression; it only adds the necessary DEFLATE framing. Level -1 (<a href="#DefaultCompression">DefaultCompression</a>) uses the default compression level. Level -2 (<a href="#HuffmanOnly">HuffmanOnly</a>) will use Huffman compression only, giving a very fast compression for all types of input, but sacrificing considerable compression efficiency. </p><p>If level is in the range [-2, 9] then the error returned will be nil. Otherwise the error returned will be non-nil. </p> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="NewWriterDict" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/deflate.go;l=676">NewWriterDict</a> <a class="Documentation-idLink" href="#NewWriterDict" title="Go to NewWriterDict" aria-label="Go to NewWriterDict">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func NewWriterDict(w <a href="/io">io</a>.<a href="/io#Writer">Writer</a>, level <a href="/builtin#int">int</a>, dict []<a href="/builtin#byte">byte</a>) (*<a href="#Writer">Writer</a>, <a href="/builtin#error">error</a>)</pre> </div> <p>NewWriterDict is like <a href="#NewWriter">NewWriter</a> but initializes the new <a href="#Writer">Writer</a> with a preset dictionary. The returned <a href="#Writer">Writer</a> behaves as if the dictionary had been written to it without producing any compressed output. The compressed data written to w can only be decompressed by a <a href="#Reader">Reader</a> initialized with the same dictionary. </p> </div><div class="Documentation-typeMethod"> <h4 tabindex="-1" id="Writer.Close" data-kind="method" class="Documentation-typeMethodHeader"> <span>func (*Writer) <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/deflate.go;l=726">Close</a> <a class="Documentation-idLink" href="#Writer.Close" title="Go to Writer.Close" aria-label="Go to Writer.Close">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func (w *<a href="#Writer">Writer</a>) Close() <a href="/builtin#error">error</a></pre> </div> <p>Close flushes and closes the writer. </p> </div><div class="Documentation-typeMethod"> <h4 tabindex="-1" id="Writer.Flush" data-kind="method" class="Documentation-typeMethodHeader"> <span>func (*Writer) <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/deflate.go;l=719">Flush</a> <a class="Documentation-idLink" href="#Writer.Flush" title="Go to Writer.Flush" aria-label="Go to Writer.Flush">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func (w *<a href="#Writer">Writer</a>) Flush() <a href="/builtin#error">error</a></pre> </div> <p>Flush flushes any pending data to the underlying writer. It is useful mainly in compressed network protocols, to ensure that a remote reader has enough data to reconstruct a packet. Flush does not return until the data has been written. Calling Flush when there is no pending data still causes the <a href="#Writer">Writer</a> to emit a sync marker of at least 4 bytes. If the underlying writer returns an error, Flush returns that error. </p><p>In the terminology of the zlib library, Flush is equivalent to Z_SYNC_FLUSH. </p> </div><div class="Documentation-typeMethod"> <h4 tabindex="-1" id="Writer.Reset" data-kind="method" class="Documentation-typeMethodHeader"> <span>func (*Writer) <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/deflate.go;l=733">Reset</a> <a class="Documentation-idLink" href="#Writer.Reset" title="Go to Writer.Reset" aria-label="Go to Writer.Reset">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.2</span> </span> </h4> <div class="Documentation-declaration"> <pre>func (w *<a href="#Writer">Writer</a>) Reset(dst <a href="/io">io</a>.<a href="/io#Writer">Writer</a>)</pre> </div> <p>Reset discards the writer&#39;s state and makes it equivalent to the result of <a href="#NewWriter">NewWriter</a> or <a href="#NewWriterDict">NewWriterDict</a> called with dst and w&#39;s level and dictionary. </p> </div><div class="Documentation-typeMethod"> <h4 tabindex="-1" id="Writer.Write" data-kind="method" class="Documentation-typeMethodHeader"> <span>func (*Writer) <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/deflate.go;l=706">Write</a> <a class="Documentation-idLink" href="#Writer.Write" title="Go to Writer.Write" aria-label="Go to Writer.Write">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func (w *<a href="#Writer">Writer</a>) Write(data []<a href="/builtin#byte">byte</a>) (n <a href="/builtin#int">int</a>, err <a href="/builtin#error">error</a>)</pre> </div> <p>Write writes data to w, which will eventually write the compressed form of data to its underlying writer. </p> </div> </div></section></div> </div> </div> <div class="UnitFiles js-unitFiles"> <h2 class="UnitFiles-title" id="section-sourcefiles"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/insert_drive_file_gm_grey_24dp.svg" alt=""> Source Files <a class="UnitFiles-idLink" href="#section-sourcefiles" title="Go to Source Files" aria-label="Go to Source Files">露</a> </h2> <div class="UnitFiles-titleLink"> <a href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate" target="_blank" rel="noopener">View all Source files</a> </div> <div> <ul class="UnitFiles-fileList"><li> <a href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/deflate.go" target="_blank" rel="noopener" title="deflate.go">deflate.go</a> </li><li> <a href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/deflatefast.go" target="_blank" rel="noopener" title="deflatefast.go">deflatefast.go</a> </li><li> <a href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/dict_decoder.go" target="_blank" rel="noopener" title="dict_decoder.go">dict_decoder.go</a> </li><li> <a href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/huffman_bit_writer.go" target="_blank" rel="noopener" title="huffman_bit_writer.go">huffman_bit_writer.go</a> </li><li> <a href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/huffman_code.go" target="_blank" rel="noopener" title="huffman_code.go">huffman_code.go</a> </li><li> <a href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/inflate.go" target="_blank" rel="noopener" title="inflate.go">inflate.go</a> </li><li> <a href="https://cs.opensource.google/go/go/+/go1.24.1:src/compress/flate/token.go" target="_blank" rel="noopener" title="token.go">token.go</a> </li></ul> </div> </div> </div> </div> <div id="showInternal-description" hidden> Click to show internal directories. </div> <div id="hideInternal-description" hidden> Click to hide internal directories. </div> </article> <footer class="go-Main-footer"></footer> </main> <footer class="go-Footer"> <div class="go-Footer-links"> <div class="go-Footer-linkColumn"> <a href="https://go.dev/solutions" class="go-Footer-link go-Footer-link--primary" data-gtmc="footer link"> Why Go </a> <a href="https://go.dev/solutions#use-cases" class="go-Footer-link" data-gtmc="footer link"> Use Cases </a> <a href="https://go.dev/solutions#case-studies" class="go-Footer-link" data-gtmc="footer link"> Case Studies </a> </div> <div class="go-Footer-linkColumn"> <a href="https://learn.go.dev/" class="go-Footer-link go-Footer-link--primary" data-gtmc="footer link"> Get Started </a> <a href="https://play.golang.org" class="go-Footer-link" data-gtmc="footer link"> Playground </a> <a href="https://tour.golang.org" class="go-Footer-link" data-gtmc="footer link"> Tour </a> <a href="https://stackoverflow.com/questions/tagged/go?tab=Newest" class="go-Footer-link" data-gtmc="footer link"> Stack Overflow </a> <a href="https://go.dev/help" class="go-Footer-link" data-gtmc="footer link"> Help </a> </div> <div class="go-Footer-linkColumn"> <a href="https://pkg.go.dev" class="go-Footer-link go-Footer-link--primary" data-gtmc="footer link"> Packages </a> <a href="/std" class="go-Footer-link" data-gtmc="footer link"> Standard Library </a> <a href="/golang.org/x" class="go-Footer-link" data-gtmc="footer link"> Sub-repositories </a> <a href="https://pkg.go.dev/about" class="go-Footer-link" data-gtmc="footer link"> About Go Packages </a> </div> <div class="go-Footer-linkColumn"> <a href="https://go.dev/project" class="go-Footer-link go-Footer-link--primary" data-gtmc="footer link"> About </a> <a href="https://go.dev/dl/" class="go-Footer-link" data-gtmc="footer link">Download</a> <a href="https://go.dev/blog" class="go-Footer-link" data-gtmc="footer link">Blog</a> <a href="https://github.com/golang/go/issues" class="go-Footer-link" data-gtmc="footer link"> Issue Tracker </a> <a href="https://go.dev/doc/devel/release.html" class="go-Footer-link" data-gtmc="footer link"> Release Notes </a> <a href="https://blog.golang.org/go-brand" class="go-Footer-link" data-gtmc="footer link"> Brand Guidelines </a> <a href="https://go.dev/conduct" class="go-Footer-link" data-gtmc="footer link"> Code of Conduct </a> </div> <div class="go-Footer-linkColumn"> <a href="https://www.twitter.com/golang" class="go-Footer-link go-Footer-link--primary" data-gtmc="footer link"> Connect </a> <a href="https://www.twitter.com/golang" class="go-Footer-link" data-gtmc="footer link"> Twitter </a> <a href="https://github.com/golang" class="go-Footer-link" data-gtmc="footer link">GitHub</a> <a href="https://invite.slack.golangbridge.org/" class="go-Footer-link" data-gtmc="footer link"> Slack </a> <a href="https://reddit.com/r/golang" class="go-Footer-link" data-gtmc="footer link"> r/golang </a> <a href="https://www.meetup.com/pro/go" class="go-Footer-link" data-gtmc="footer link"> Meetup </a> <a href="https://golangweekly.com/" class="go-Footer-link" data-gtmc="footer link"> Golang Weekly </a> </div> </div> <div class="go-Footer-bottom"> <img class="go-Footer-gopher" width="1431" height="901" src="/static/shared/gopher/pilot-bust-1431x901.svg" alt="Gopher in flight goggles"> <ul class="go-Footer-listRow"> <li class="go-Footer-listItem"> <a href="https://go.dev/copyright" data-gtmc="footer link">Copyright</a> </li> <li class="go-Footer-listItem"> <a href="https://go.dev/tos" data-gtmc="footer link">Terms of Service</a> </li> <li class="go-Footer-listItem"> <a href="http://www.google.com/intl/en/policies/privacy/" data-gtmc="footer link" target="_blank" rel="noopener"> Privacy Policy </a> </li> <li class="go-Footer-listItem"> <a href="https://go.dev/s/pkgsite-feedback" target="_blank" rel="noopener" data-gtmc="footer link"> Report an Issue </a> </li> <li class="go-Footer-listItem"> <button class="go-Button go-Button--text go-Footer-toggleTheme js-toggleTheme" aria-label="Theme Toggle"> <img data-value="auto" class="go-Icon go-Icon--inverted" height="24" width="24" src="/static/shared/icon/brightness_6_gm_grey_24dp.svg" alt="System theme"> <img data-value="dark" class="go-Icon go-Icon--inverted" height="24" width="24" src="/static/shared/icon/brightness_2_gm_grey_24dp.svg" alt="Dark theme"> <img data-value="light" class="go-Icon go-Icon--inverted" height="24" width="24" src="/static/shared/icon/light_mode_gm_grey_24dp.svg" alt="Light theme"> <p> Theme Toggle </p> </button> </li> <li class="go-Footer-listItem"> <button class="go-Button go-Button--text go-Footer-keyboard js-openShortcuts" aria-label="Shorcuts Modal"> <img class="go-Icon go-Icon--inverted" height="24" width="24" src="/static/shared/icon/keyboard_grey_24dp.svg" alt=""> <p> Shortcuts Modal </p> </button> </li> </ul> <a class="go-Footer-googleLogo" href="https://google.com" target="_blank"rel="noopener" data-gtmc="footer link"> <img class="go-Footer-googleLogoImg" height="24" width="72" src="/static/shared/logo/google-white.svg" alt="Google logo"> </a> </div> </footer> <dialog id="jump-to-modal" class="JumpDialog go-Modal go-Modal--md js-modal"> <form method="dialog" data-gmtc="jump to form" aria-label="Jump to Identifier"> <div class="Dialog-title go-Modal-header"> <h2>Jump to</h2> <button class="go-Button go-Button--inline" type="button" data-modal-close data-gtmc="modal button" aria-label="Close" > <img class="go-Icon" height="24" width="24" src="/static/shared/icon/close_gm_grey_24dp.svg" alt="" /> </button> </div> <div class="JumpDialog-filter"> <input class="JumpDialog-input go-Input" autocomplete="off" type="text"> </div> <div class="JumpDialog-body go-Modal-body"> <div class="JumpDialog-list"></div> </div> <div class="go-Modal-actions"> <button class="go-Button" data-test-id="close-dialog">Close</button> </div> </form> </dialog> <dialog class="ShortcutsDialog go-Modal go-Modal--sm js-modal"> <form method="dialog"> <div class="go-Modal-header"> <h2>Keyboard shortcuts</h2> <button class="go-Button go-Button--inline" type="button" data-modal-close data-gtmc="modal button" aria-label="Close" > <img class="go-Icon" height="24" width="24" src="/static/shared/icon/close_gm_grey_24dp.svg" alt="" /> </button> </div> <div class="go-Modal-body"> <table> <tbody> <tr><td class="ShortcutsDialog-key"> <strong>?</strong></td><td> : This menu</td> </tr> <tr><td class="ShortcutsDialog-key"> <strong>/</strong></td><td> : Search site</td> </tr> <tr><td class="ShortcutsDialog-key"> <strong>f</strong> or <strong>F</strong></td><td> : Jump to</td> </tr> <tr> <td class="ShortcutsDialog-key"><strong>y</strong> or <strong>Y</strong></td> <td> : Canonical URL</td> </tr> </tbody> </table> </div> <div class="go-Modal-actions"> <button class="go-Button" data-test-id="close-dialog">Close</button> </div> </form> </dialog> <section class="Cookie-notice js-cookieNotice"> <div>go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic. <a target=_blank href="https://policies.google.com/technologies/cookies">Learn more.</a></div> <div><button class="go-Button">Okay</button></div> </section> <script> // this will throw if the querySelector can鈥檛 find the element const gtmId = document.querySelector('.js-gtmID').dataset.gtmid; if (!gtmId) { throw new Error('Google Tag Manager ID not found'); } loadScript(`https://www.googletagmanager.com/gtm.js?id=${gtmId}`); </script> <noscript> <iframe src="https://www.googletagmanager.com/ns.html?id=GTM-W8MVQXG" height="0" width="0" style="display:none;visibility:hidden"> </iframe> </noscript> <div class="js-canonicalURLPath" data-canonical-url-path="/compress/flate@go1.24.1" hidden></div> <div class="js-playgroundVars" data-modulepath="std" data-version="v1.24.1" hidden></div> <script> loadScript('/static/frontend/unit/main/main.js') </script> <script> loadScript('/static/frontend/unit/unit.js') </script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10