-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update module for getting stdin, and remove get-stdin package
- Loading branch information
Showing
7 changed files
with
39 additions
and
57 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import streamConsumers from 'node:stream/consumers' | ||
import { setTimeout as setTimeoutPromise } from 'node:timers/promises' | ||
import chalk from 'chalk' | ||
import { info } from '../cli' | ||
import { debug } from './debug' | ||
|
||
const STDIN_NOTICE_DELAY = 3000 | ||
|
||
export const getStdin = async (): Promise<Buffer> => { | ||
if (process.stdin.isTTY) return Buffer.alloc(0) | ||
|
||
const delayedNoticeController = new AbortController() | ||
|
||
setTimeoutPromise(STDIN_NOTICE_DELAY, null, { | ||
ref: false, | ||
signal: delayedNoticeController.signal, | ||
}) | ||
.then(() => { | ||
info( | ||
`Currently waiting data from stdin stream. Conversion will start after finished reading. (Pass ${chalk.yellow`--no-stdin`} option if it was not intended)` | ||
) | ||
}) | ||
.catch(() => { | ||
// No ops | ||
}) | ||
|
||
debug('Reading stdin stream...') | ||
const buf = await streamConsumers.buffer(process.stdin) | ||
|
||
debug('Read from stdin: %d bytes', buf.length) | ||
delayedNoticeController.abort() | ||
|
||
return buf | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters