diff --git a/docs/build/messages.md b/docs/build/messages.md index 18b130292..5557d729a 100644 --- a/docs/build/messages.md +++ b/docs/build/messages.md @@ -342,3 +342,67 @@ val decodedMessage = conversation.decode(envelope) + +## Compress message content + +Compress message content using a supported compression algorithm. + + + + +Message content can be optionally compressed using the `compression` option. The value of the option is the name of the compression algorithm to use. Currently supported are `gzip` and `deflate`. Compression is applied to the bytes produced by the content codec. + +Content will be decompressed transparently on the receiving end. Note that `Client` enforces maximum content size. The default limit can be overridden through the `ClientOptions`. Consequently, a message that would expand beyond that limit on the receiving end will fail to decode. + +```ts +import { Compression } from "@xmtp/xmtp-js"; + +conversation.send("#".repeat(1000), { + compression: Compression.COMPRESSION_DEFLATE, +}); +``` + + + + +Message content can be optionally compressed using the compression option. The value of the option is the name of the compression algorithm to use. Currently supported are gzip and deflate. Compression is applied to the bytes produced by the content codec. + +Content will be decompressed transparently on the receiving end. Note that `Client` enforces maximum content size. The default limit can be overridden through the `ClientOptions`. Consequently, a message that would expand beyond that limit on the receiving end will fail to decode. + +```swift +try await conversation.send(text: '#'.repeat(1000), options: .init(compression: .gzip)) +``` + + + + +Message content can be optionally compressed using the compression option. The value of the option is the name of the compression algorithm to use. Currently supported are gzip and deflate. Compression is applied to the bytes produced by the content codec. + +Content will be decompressed transparently on the receiving end. Note that `Client` enforces maximum content size. The default limit can be overridden through the `ClientOptions`. Consequently, a message that would expand beyond that limit on the receiving end will fail to decode. + +```kotlin +conversation.send( + text = '#'.repeat(1000), + options = ClientOptions.Api(compression = EncodedContentCompression.GZIP) +) +``` + + + + +Message content can be optionally compressed using the `compression` option. The value of the option is the name of the compression algorithm to use. Currently supported are `gzip` and `deflate`. Compression is applied to the bytes produced by the content codec. + +Content will be decompressed transparently on the receiving end. Note that `Client` enforces maximum content size. The default limit can be overridden through the `ClientOptions`. Consequently, a message that would expand beyond that limit on the receiving end will fail to decode. + +```tsx +import { Compression, ContentTypeText } from "@xmtp/react-sdk"; + +const sendMessage = useSendMessage(); + +await sendMessage(conversation, "#".repeat(1000), ContentTypeText, { + compression: Compression.COMPRESSION_DEFLATE, +}); +``` + + + diff --git a/docs/launch/performance.md b/docs/launch/performance.md index fe07ed1a4..833b91b87 100644 --- a/docs/launch/performance.md +++ b/docs/launch/performance.md @@ -36,67 +36,7 @@ To learn more, see [List messages in a conversation with pagination](/docs/build ## Compress message content -Compress message content using a supported compression algorithm. - - - - -Message content can be optionally compressed using the `compression` option. The value of the option is the name of the compression algorithm to use. Currently supported are `gzip` and `deflate`. Compression is applied to the bytes produced by the content codec. - -Content will be decompressed transparently on the receiving end. Note that `Client` enforces maximum content size. The default limit can be overridden through the `ClientOptions`. Consequently, a message that would expand beyond that limit on the receiving end will fail to decode. - -```ts -import { Compression } from "@xmtp/xmtp-js"; - -conversation.send("#".repeat(1000), { - compression: Compression.COMPRESSION_DEFLATE, -}); -``` - - - - -Message content can be optionally compressed using the compression option. The value of the option is the name of the compression algorithm to use. Currently supported are gzip and deflate. Compression is applied to the bytes produced by the content codec. - -Content will be decompressed transparently on the receiving end. Note that `Client` enforces maximum content size. The default limit can be overridden through the `ClientOptions`. Consequently, a message that would expand beyond that limit on the receiving end will fail to decode. - -```swift -try await conversation.send(text: '#'.repeat(1000), options: .init(compression: .gzip)) -``` - - - - -Message content can be optionally compressed using the compression option. The value of the option is the name of the compression algorithm to use. Currently supported are gzip and deflate. Compression is applied to the bytes produced by the content codec. - -Content will be decompressed transparently on the receiving end. Note that `Client` enforces maximum content size. The default limit can be overridden through the `ClientOptions`. Consequently, a message that would expand beyond that limit on the receiving end will fail to decode. - -```kotlin -conversation.send( - text = '#'.repeat(1000), - options = ClientOptions.Api(compression = EncodedContentCompression.GZIP) -) -``` - - - - -Message content can be optionally compressed using the `compression` option. The value of the option is the name of the compression algorithm to use. Currently supported are `gzip` and `deflate`. Compression is applied to the bytes produced by the content codec. - -Content will be decompressed transparently on the receiving end. Note that `Client` enforces maximum content size. The default limit can be overridden through the `ClientOptions`. Consequently, a message that would expand beyond that limit on the receiving end will fail to decode. - -```tsx -import { Compression, ContentTypeText } from '@xmtp/react-sdk' - -const sendMessage = useSendMessage(); - -await sendMessage(conversation, '#'.repeat(1000), ContentTypeText, { - compression: Compression.COMPRESSION_DEFLATE, -}) -``` - - - +Compress message content using a supported compression algorithm. To learn more, see [Compress message content](/docs/build/messages#compress-message-content). ## Optimize web rendering