@atproto/common
Advanced tools
Comparing version 0.4.3 to 0.4.4
# @atproto/common | ||
## 0.4.4 | ||
### Patch Changes | ||
- [#2834](https://github.com/bluesky-social/atproto/pull/2834) [`4098d9890`](https://github.com/bluesky-social/atproto/commit/4098d9890173f4d6c6512f2d8994eebbf12b5e13) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Allow contentEncoding to be an array for consistency with typing of headers | ||
## 0.4.3 | ||
@@ -4,0 +10,0 @@ |
@@ -18,9 +18,11 @@ /// <reference types="node" /> | ||
} | ||
export declare function decodeStream(stream: Readable, contentEncoding?: string): Readable; | ||
export declare function decodeStream(stream: AsyncIterable<Uint8Array>, contentEncoding?: string): AsyncIterable<Uint8Array> | Readable; | ||
export declare function decodeStream(stream: Readable, contentEncoding?: string | string[]): Readable; | ||
export declare function decodeStream(stream: AsyncIterable<Uint8Array>, contentEncoding?: string | string[]): AsyncIterable<Uint8Array> | Readable; | ||
/** | ||
* Create a series of decoding streams based on the content-encoding header. The | ||
* resulting streams should be piped together to decode the content. | ||
* | ||
* @see {@link https://datatracker.ietf.org/doc/html/rfc9110#section-8.4.1} | ||
*/ | ||
export declare function createDecoders(contentEncoding?: string): Duplex[]; | ||
export declare function createDecoders(contentEncoding?: string | string[]): Duplex[]; | ||
//# sourceMappingURL=streams.d.ts.map |
@@ -104,9 +104,17 @@ "use strict"; | ||
* resulting streams should be piped together to decode the content. | ||
* | ||
* @see {@link https://datatracker.ietf.org/doc/html/rfc9110#section-8.4.1} | ||
*/ | ||
function createDecoders(contentEncoding) { | ||
const decoders = []; | ||
if (contentEncoding) { | ||
const encodings = contentEncoding.split(','); | ||
if (contentEncoding?.length) { | ||
const encodings = Array.isArray(contentEncoding) | ||
? contentEncoding.flatMap(commaSplit) | ||
: contentEncoding.split(','); | ||
for (const encoding of encodings) { | ||
const normalizedEncoding = normalizeEncoding(encoding); | ||
// @NOTE | ||
// > The default (identity) encoding [...] is used only in the | ||
// > Accept-Encoding header, and SHOULD NOT be used in the | ||
// > Content-Encoding header. | ||
if (normalizedEncoding === 'identity') | ||
@@ -120,2 +128,5 @@ continue; | ||
exports.createDecoders = createDecoders; | ||
function commaSplit(header) { | ||
return header.split(','); | ||
} | ||
function normalizeEncoding(encoding) { | ||
@@ -122,0 +133,0 @@ // https://www.rfc-editor.org/rfc/rfc7231#section-3.1.2.1 |
{ | ||
"name": "@atproto/common", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Shared web-platform-friendly code for atproto libraries", |
@@ -91,11 +91,11 @@ import { | ||
stream: Readable, | ||
contentEncoding?: string, | ||
contentEncoding?: string | string[], | ||
): Readable | ||
export function decodeStream( | ||
stream: AsyncIterable<Uint8Array>, | ||
contentEncoding?: string, | ||
contentEncoding?: string | string[], | ||
): AsyncIterable<Uint8Array> | Readable | ||
export function decodeStream( | ||
stream: Readable | AsyncIterable<Uint8Array>, | ||
contentEncoding?: string, | ||
contentEncoding?: string | string[], | ||
): Readable | AsyncIterable<Uint8Array> { | ||
@@ -110,10 +110,19 @@ const decoders = createDecoders(contentEncoding) | ||
* resulting streams should be piped together to decode the content. | ||
* | ||
* @see {@link https://datatracker.ietf.org/doc/html/rfc9110#section-8.4.1} | ||
*/ | ||
export function createDecoders(contentEncoding?: string): Duplex[] { | ||
export function createDecoders(contentEncoding?: string | string[]): Duplex[] { | ||
const decoders: Duplex[] = [] | ||
if (contentEncoding) { | ||
const encodings = contentEncoding.split(',') | ||
if (contentEncoding?.length) { | ||
const encodings: string[] = Array.isArray(contentEncoding) | ||
? contentEncoding.flatMap(commaSplit) | ||
: contentEncoding.split(',') | ||
for (const encoding of encodings) { | ||
const normalizedEncoding = normalizeEncoding(encoding) | ||
// @NOTE | ||
// > The default (identity) encoding [...] is used only in the | ||
// > Accept-Encoding header, and SHOULD NOT be used in the | ||
// > Content-Encoding header. | ||
if (normalizedEncoding === 'identity') continue | ||
@@ -128,2 +137,6 @@ | ||
function commaSplit(header: string): string[] { | ||
return header.split(',') | ||
} | ||
function normalizeEncoding(encoding: string) { | ||
@@ -130,0 +143,0 @@ // https://www.rfc-editor.org/rfc/rfc7231#section-3.1.2.1 |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
85519
1632