Skip to content

Commit

Permalink
export ProgressStream class
Browse files Browse the repository at this point in the history
  • Loading branch information
talentlessguy committed Jan 28, 2025
1 parent b827bc0 commit 1e706a7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion example/progress.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import http from 'node:http'
import progressStream from '../src/progress'
import progressStream from 'dunai/progress'

const str = progressStream({
drain: true,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"@types/node": "^22.10.10",
"expect": "^29.7.0",
"tsx": "^4.19.2",
"typescript": "^5.7.3"
"typescript": "^5.7.3",
"dunai": "link:./"
},
"exports": {
"./concat": {
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

6 changes: 3 additions & 3 deletions src/progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface ProgressUpdate {

type ProgressCallback = (update: ProgressUpdate) => void

interface ProgressStream extends Transform {
export interface ProgressStream extends Transform {
on(event: string | symbol, listener: (...args: any[]) => void): this
on(event: 'length', listener: (length: number) => void): this
on(event: 'progress', listener: (update: ProgressUpdate) => void): this
Expand All @@ -67,7 +67,7 @@ interface ProgressStream extends Transform {
emit(event: 'progress', update: ProgressUpdate): boolean
}

class ProgressStream extends Transform {
export class ProgressStream extends Transform {
#length: number
#time: number
#drain: boolean
Expand Down Expand Up @@ -183,6 +183,6 @@ class ProgressStream extends Transform {
}
}

export default function progressStream(options?: ProgressOptions | ProgressCallback, onprogress?: ProgressCallback) {
export function createProgressStream(options?: ProgressOptions | ProgressCallback, onprogress?: ProgressCallback) {
return new ProgressStream(options, onprogress)
}
6 changes: 3 additions & 3 deletions test/progress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from 'node:assert/strict'
import { Readable, Transform } from 'node:stream'
import { pipeline } from 'node:stream/promises'
import { beforeEach, describe, it, mock } from 'node:test'
import progressStream from '../src/progress'
import { createProgressStream } from '../src/progress'
import type { ProgressUpdate } from '../src/progress'

const sampleData = Buffer.alloc(1024 * 10)
Expand All @@ -22,7 +22,7 @@ describe('ProgressStream', () => {
})

async function runTestStream(options: any = {}, data = sampleData) {
const stream = progressStream({
const stream = createProgressStream({
time: 10,
drain: true,
...options
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('ProgressStream', () => {
})

it('should handle dynamic length updates via setLength', async () => {
const stream = progressStream({ time: 10, drain: true })
const stream = createProgressStream({ time: 10, drain: true })
const onProgress = mock.fn((update: ProgressUpdate) => {
lastUpdate = update
})
Expand Down

0 comments on commit 1e706a7

Please sign in to comment.