Skip to content

Commit

Permalink
feat: return Uint8Array instead of ArrayBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
younggglcy committed Nov 19, 2023
1 parent 3f5056b commit d94dcb4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type ArrayBufferEncodingOption = 'array-buffer';
type GetStdoutStderrType<EncodingType extends EncodingOption> = EncodingType extends BufferEncodingOption
? Buffer
: EncodingType extends ArrayBufferEncodingOption
? ArrayBuffer
? Uint8Array
: string;

export type CommonOptions<EncodingType extends EncodingOption = DefaultEncodingOption> = {
Expand Down Expand Up @@ -329,7 +329,7 @@ export type NodeOptions<EncodingType extends EncodingOption = DefaultEncodingOpt
readonly nodeOptions?: string[];
} & Options<EncodingType>;

type StdoutStderrAll = string | Buffer | ArrayBuffer | undefined;
type StdoutStderrAll = string | Buffer | Uint8Array | undefined;

export type ExecaReturnBase<StdoutStderrType extends StdoutStderrAll> = {
/**
Expand Down Expand Up @@ -772,9 +772,9 @@ export function execaCommandSync<EncodingType extends EncodingOption = DefaultEn
type TemplateExpression =
| string
| number
| ExecaReturnValue<string | Buffer | ArrayBuffer>
| ExecaSyncReturnValue<string | Buffer | ArrayBuffer>
| Array<string | number | ExecaReturnValue<string | Buffer | ArrayBuffer> | ExecaSyncReturnValue<string | Buffer | ArrayBuffer>>;
| ExecaReturnValue<string | Buffer | Uint8Array>
| ExecaSyncReturnValue<string | Buffer | Uint8Array>
| Array<string | number | ExecaReturnValue<string | Buffer | Uint8Array> | ExecaSyncReturnValue<string | Buffer | Uint8Array>>;

type Execa$<StdoutStderrType extends StdoutStderrAll = string> = {
/**
Expand Down Expand Up @@ -803,7 +803,7 @@ type Execa$<StdoutStderrType extends StdoutStderrAll = string> = {
(options: Options<undefined>): Execa$<StdoutStderrType>;
(options: Options): Execa$;
(options: Options<BufferEncodingOption>): Execa$<Buffer>;
(options: Options<ArrayBufferEncodingOption>): Execa$<ArrayBuffer>;
(options: Options<ArrayBufferEncodingOption>): Execa$<Uint8Array>;
(
templates: TemplateStringsArray,
...expressions: TemplateExpression[]
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const handleOutput = (options, value, error) => {
return value instanceof ArrayBuffer ? stripFinalNewlineForArrayBuffer(value) : stripFinalNewline(value);
}

return value;
return value instanceof ArrayBuffer ? new Uint8Array(value) : value;
};

export function execa(file, args, options) {
Expand Down
2 changes: 1 addition & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export function stripFinalNewlineForArrayBuffer(arrayBuffer) {
input = input.slice(0, -1);
}

Check warning on line 14 in lib/buffer.js

View check run for this annotation

Codecov / codecov/patch

lib/buffer.js#L13-L14

Added lines #L13 - L14 were not covered by tests

return input.buffer;
return input;
}
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,19 +399,19 @@ The numeric exit code of the process that was run.

#### stdout

Type: `string | Buffer | ArrayBuffer`
Type: `string | Buffer | Uint8Array`

The output of the process on stdout.

#### stderr

Type: `string | Buffer | ArrayBuffer`
Type: `string | Buffer | Uint8Array`

The output of the process on stderr.

#### all

Type: `string | Buffer | ArrayBuffer | undefined`
Type: `string | Buffer | Uint8Array | undefined`

The output of the process with `stdout` and `stderr` interleaved.

Expand Down Expand Up @@ -683,7 +683,7 @@ Type: `string | null`\
Default: `utf8`

Specify the character encoding used to decode the `stdout` and `stderr` output. If set to `'buffer'` or `null`, then `stdout` and `stderr` will be a `Buffer` instead of a string.
If set to `'array-buffer'`, then `stdout` and `stderr` will be an `ArrayBuffer`.
If set to `'array-buffer'`, then `stdout` and `stderr` will be processed as ArrayBuffer under the hood and finally returned as an `Uint8Array`.

#### timeout

Expand Down

0 comments on commit d94dcb4

Please sign in to comment.