-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add
idResolvers
support. Add export of Integrated Resolvers. A…
…dd `PureBrotliCompressionResolver` and `WasmBrotliCompressionResolver` (for different env support)
- Loading branch information
Showing
19 changed files
with
355 additions
and
60 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
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,29 @@ | ||
import { MessageEvent } from "ws"; | ||
import brotli from "brotli"; | ||
import { Buffer } from "buffer"; | ||
import { BufferLike } from "../utils/websocketModifier.util"; | ||
import { CompressResolver } from "./index"; | ||
|
||
export default class PureBrotliCompressionResolver extends CompressResolver { | ||
public static typeName(): string { | ||
return "PureBrotli"; | ||
} | ||
|
||
public static isCompatibleWith(type: string): boolean { | ||
return [this.typeName(), "WasmBrotli"].indexOf(type) !== -1; | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
public async compress(messageEvent: object): Promise<BufferLike> { | ||
return brotli.compress(Buffer.from(JSON.stringify(messageEvent)), { | ||
quality: 0, | ||
}); | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
public async decompress(messageEvent: MessageEvent): Promise<object> { | ||
return JSON.parse( | ||
brotli.decompress(<Buffer>messageEvent.data).toString() | ||
); | ||
} | ||
} |
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,31 @@ | ||
import WebSocket from "ws"; | ||
import * as brotli from "brotli-wasm"; | ||
import { Buffer } from "buffer"; | ||
import { CompressResolver } from "./index"; | ||
import { BufferLike } from "../utils/websocketModifier.util"; | ||
|
||
export default class WasmBrotliCompressionResolver extends CompressResolver { | ||
public static typeName(): string { | ||
return "WasmBrotli"; | ||
} | ||
|
||
public static isCompatibleWith(type: string): boolean { | ||
return [this.typeName(), "PureBrotli"].indexOf(type) !== -1; | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
public async compress(messageEvent: object): Promise<BufferLike> { | ||
return brotli.compress(Buffer.from(JSON.stringify(messageEvent)), { | ||
quality: 0, | ||
}); | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
public async decompress( | ||
messageEvent: WebSocket.MessageEvent | ||
): Promise<object> { | ||
return JSON.parse( | ||
brotli.decompress(<Uint8Array>messageEvent.data).toString() | ||
); | ||
} | ||
} |
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
Oops, something went wrong.