> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/nodejs/userland-migrations/llms.txt
> Use this file to discover all available pages before exploring further.

# zlib.bytesRead to zlib.bytesWritten

> Migrate deprecated zlib.bytesRead property to zlib.bytesWritten for Node.js DEP0108

This codemod replaces `zlib.bytesRead` with `zlib.bytesWritten` for consistent stream property naming to handle Node.js [DEP0108](https://nodejs.org/api/deprecations.html#DEP0108).

## What It Does

This codemod:

* Replaces `bytesRead` property with `bytesWritten` in all zlib transform streams
* Handles both CommonJS and ESM imports
* Works with all zlib stream types (Gzip, Deflate, Inflate, etc.)

## Before/After Examples

### Basic Usage with Gzip

**Before:**

```javascript theme={null}
const zlib = require("node:zlib");
const gzip = zlib.createGzip();
gzip.on("end", () => {
  console.log("Bytes processed:", gzip.bytesRead);
});
```

**After:**

```javascript theme={null}
const zlib = require("node:zlib");
const gzip = zlib.createGzip();
gzip.on("end", () => {
  console.log("Bytes processed:", gzip.bytesWritten);
});
```

### Statistics Object

**Before:**

```javascript theme={null}
const zlib = require("node:zlib");
const deflate = zlib.createDeflate();
deflate.on("finish", () => {
  const stats = {
    input: deflate.bytesRead,
    output: deflate.bytesWritten
  };
});
```

**After:**

```javascript theme={null}
const zlib = require("node:zlib");
const deflate = zlib.createDeflate();
deflate.on("finish", () => {
  const stats = {
    input: deflate.bytesWritten,
    output: deflate.bytesWritten
  };
});
```

### Progress Tracking

**Before:**

```javascript theme={null}
const zlib = require("node:zlib");
function trackProgress(stream) {
  setInterval(() => {
    console.log(`Progress: ${stream.bytesRead} bytes`);
  }, 1000);
}
```

**After:**

```javascript theme={null}
const zlib = require("node:zlib");
function trackProgress(stream) {
  setInterval(() => {
    console.log(`Progress: ${stream.bytesWritten} bytes`);
  }, 1000);
}
```

### ESM Import

**Before:**

```javascript theme={null}
import { createGzip } from "node:zlib";
const gzip = createGzip();
const bytesProcessed = gzip.bytesRead;
```

**After:**

```javascript theme={null}
import { createGzip } from "node:zlib";
const gzip = createGzip();
const bytesProcessed = gzip.bytesWritten;
```

### Destructured Require

**Before:**

```javascript theme={null}
const { createGzip } = require("node:zlib");
const gzip = createGzip();
const bytes = gzip.bytesRead;
```

**After:**

```javascript theme={null}
const { createGzip } = require("node:zlib");
const gzip = createGzip();
const bytes = gzip.bytesWritten;
```

## Usage

Run this codemod on your project:

```bash theme={null}
npx codemod node/userland/zlib-bytesread-to-byteswritten
```

<Warning>
  The property name change from `bytesRead` to `bytesWritten` may seem counterintuitive, but it aligns with the stream's perspective: bytes written to the compression/decompression stream.
</Warning>

<Tip>
  This codemod works with all zlib compression streams including `createGzip()`, `createGunzip()`, `createDeflate()`, `createInflate()`, `createDeflateRaw()`, `createInflateRaw()`, `createUnzip()`, and `createBrotliCompress()`/`createBrotliDecompress()`.
</Tip>

## Related Deprecations

* [DEP0108: zlib.bytesRead](https://nodejs.org/api/deprecations.html#DEP0108)
