-
Notifications
You must be signed in to change notification settings - Fork 871
feat: add Content-Encoding option for file operations #1125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d56c887
feat: add Content-Encoding option to sandbox file operations
mishushakov 241bac8
test: add content-encoding gzip tests for JS and Python SDKs
mishushakov 74422df
refactor: collapse TextIOBase/IOBase branches in gzip handling
mishushakov b15a8f7
changeset
mishushakov 0d71aee
fix: assert bytearray instead of bytes in Python gzip tests
mishushakov b43faff
fix: use Accept-Encoding instead of Content-Encoding for GET requests
mishushakov 6ef9fce
Merge branch 'main' into mishushakov/content-encoding
mishushakov cc5e56f
refactor: rename contentEncoding/content_encoding to encoding
mishushakov 9bdae77
fix: resolve typecheck errors in Python SDK filesystem
mishushakov a5544f8
Merge branch 'main' into mishushakov/content-encoding
mishushakov 4c543a7
refactor: scope encoding and format opts to read/write methods in JS SDK
mishushakov 5fa3106
Merge branch 'main' into mishushakov/content-encoding
mishushakov d9151b8
fix: gzip compress entire multipart body instead of individual parts
mishushakov 09e0278
fix: use application/octet-stream for file uploads instead of multipart
mishushakov a95b765
feat: stream file uploads directly without buffering
mishushakov 2779acf
refactor: extract upload body helpers into shared utils
mishushakov 3b0ff29
refactor: replace encoding param with gzip boolean
mishushakov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,6 @@ | ||
| --- | ||
| '@e2b/python-sdk': patch | ||
| 'e2b': patch | ||
| --- | ||
|
|
||
| added gzip support for sandbox file/upload download |
This file contains hidden or 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 hidden or 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 hidden or 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
94 changes: 94 additions & 0 deletions
94
packages/js-sdk/tests/sandbox/files/contentEncoding.test.ts
This file contains hidden or 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,94 @@ | ||
| import { assert } from 'vitest' | ||
|
|
||
| import { WriteEntry } from '../../../src/sandbox/filesystem' | ||
| import { isDebug, sandboxTest } from '../../setup.js' | ||
|
|
||
| sandboxTest( | ||
| 'write and read file with gzip content encoding', | ||
| async ({ sandbox }) => { | ||
| const filename = 'test_gzip_write.txt' | ||
| const content = 'This is a test file with gzip encoding.' | ||
|
|
||
| const info = await sandbox.files.write(filename, content, { | ||
| gzip: true, | ||
| }) | ||
| assert.equal(info.name, filename) | ||
| assert.equal(info.type, 'file') | ||
| assert.equal(info.path, `/home/user/${filename}`) | ||
|
|
||
| const readContent = await sandbox.files.read(filename, { | ||
| gzip: true, | ||
| }) | ||
| assert.equal(readContent, content) | ||
|
|
||
| if (isDebug) { | ||
| await sandbox.files.remove(filename) | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| sandboxTest( | ||
| 'write with gzip and read without encoding', | ||
| async ({ sandbox }) => { | ||
| const filename = 'test_gzip_write_plain_read.txt' | ||
| const content = 'Written with gzip, read without.' | ||
|
|
||
| await sandbox.files.write(filename, content, { | ||
| gzip: true, | ||
| }) | ||
|
|
||
| const readContent = await sandbox.files.read(filename) | ||
| assert.equal(readContent, content) | ||
|
|
||
| if (isDebug) { | ||
| await sandbox.files.remove(filename) | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| sandboxTest('writeFiles with gzip content encoding', async ({ sandbox }) => { | ||
| const files: WriteEntry[] = [ | ||
| { path: 'gzip_multi_1.txt', data: 'File 1 content' }, | ||
| { path: 'gzip_multi_2.txt', data: 'File 2 content' }, | ||
| { path: 'gzip_multi_3.txt', data: 'File 3 content' }, | ||
| ] | ||
|
|
||
| const infos = await sandbox.files.writeFiles(files, { | ||
| gzip: true, | ||
| }) | ||
|
|
||
| assert.equal(infos.length, files.length) | ||
|
|
||
| for (let i = 0; i < files.length; i++) { | ||
| const readContent = await sandbox.files.read(files[i].path) | ||
| assert.equal(readContent, files[i].data) | ||
| } | ||
|
|
||
| if (isDebug) { | ||
| for (const file of files) { | ||
| await sandbox.files.remove(file.path) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| sandboxTest( | ||
| 'read file as bytes with gzip content encoding', | ||
| async ({ sandbox }) => { | ||
| const filename = 'test_gzip_bytes.txt' | ||
| const content = 'Binary content with gzip.' | ||
|
|
||
| await sandbox.files.write(filename, content) | ||
|
|
||
| const readBytes = await sandbox.files.read(filename, { | ||
| format: 'bytes', | ||
| gzip: true, | ||
| }) | ||
| assert.instanceOf(readBytes, Uint8Array) | ||
| const decoded = new TextDecoder().decode(readBytes) | ||
| assert.equal(decoded, content) | ||
|
|
||
| if (isDebug) { | ||
| await sandbox.files.remove(filename) | ||
| } | ||
| } | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.