Skip to content

Commit

Permalink
compress
Browse files Browse the repository at this point in the history
  • Loading branch information
humanagent committed Sep 1, 2023
1 parent 446f15b commit 85a08ab
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 61 deletions.
64 changes: 64 additions & 0 deletions docs/build/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,67 @@ val decodedMessage = conversation.decode(envelope)

</TabItem>
</Tabs>

## Compress message content

Compress message content using a supported compression algorithm.

<Tabs groupId="sdk-langs">
<TabItem value="js" label="JavaScript" attributes={{className: "js_tab"}}>

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,
});
```

</TabItem>
<TabItem value="swift" label="Swift" attributes={{className: "swift_tab"}}>

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))
```

</TabItem>
<TabItem value="kotlin" label="Kotlin" attributes={{className: "kotlin_tab"}}>

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)
)
```

</TabItem>
<TabItem value="react" label="React" attributes={{className: "react_tab"}}>

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,
});
```

</TabItem>
</Tabs>
62 changes: 1 addition & 61 deletions docs/launch/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<Tabs groupId="sdk-langs">
<TabItem value="js" label="JavaScript" attributes={{className: "js_tab"}}>

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,
});
```

</TabItem>
<TabItem value="swift" label="Swift" attributes={{className: "swift_tab"}}>

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))
```

</TabItem>
<TabItem value="kotlin" label="Kotlin" attributes={{className: "kotlin_tab"}}>

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)
)
```

</TabItem>
<TabItem value="react" label="React" attributes={{className: "react_tab"}}>

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,
})
```

</TabItem>
</Tabs>
Compress message content using a supported compression algorithm. To learn more, see [Compress message content](/docs/build/messages#compress-message-content).

## Optimize web rendering

Expand Down

1 comment on commit 85a08ab

@vercel
Copy link

@vercel vercel bot commented on 85a08ab Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.