Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

feat(sdk): add gzip option to template copy layer (#1482)

Mish Ushakov2b7dd17f10ae
diff --git a/.changeset/copy-compression-option.md b/.changeset/copy-compression-option.md
new file mode 100644
index 000000000..c53aa2a4f
--- /dev/null
+++ b/.changeset/copy-compression-option.md
@@ -0,0 +1,22 @@
+---
+"e2b": minor
+"@e2b/python-sdk": minor
+---
+
+Add a `gzip` option to the template `copy` layer to control whether copied
+files are gzipped before upload.
+
+Gzip is enabled by default (matching the previous behavior). Pass
+`gzip: false` (`gzip=False` in Python) to upload an uncompressed tar archive
+instead — useful when copying already-compressed files where gzipping adds
+CPU cost without shrinking the payload.
+
+```ts
+// JS/TS
+template.copy('model.bin', '/app/', { gzip: false })
+```
+
+```python
+# Python
+template.copy('model.bin', '/app/', gzip=False)
+```
diff --git a/packages/js-sdk/src/template/buildApi.ts b/packages/js-sdk/src/template/buildApi.ts
index 581d26eba..8b48b62ce 100644
--- a/packages/js-sdk/src/template/buildApi.ts
+++ b/packages/js-sdk/src/template/buildApi.ts
@@ -111,6 +111,7 @@ export async function uploadFile(
url: string
ignorePatterns: string[]
resolveSymlinks: boolean
+ gzip: boolean
},
stackTrace: string | undefined,
// Uploads (PUT to S3 presigned URL) can take a long time for large
@@ -120,8 +121,14 @@ export async function uploadFile(
// via `signal`) to override.
abortOpts?: { signal?: AbortSignal; requestTimeoutMs?: number }
) {
- const { fileName, url, fileContextPath, ignorePatterns, resolveSymlinks } =
- options
+ const {
+ fileName,
+ url,
+ fileContextPath,
+ ignorePatterns,
+ resolveSymlinks,
+ gzip,
+ } = options
// Spool the archive to a temporary file and stream it from disk instead of
// buffering in memory. S3 presigned PUT URLs reject Transfer-Encoding:
// chunked with 501 NotImplemented (see e2b-dev/e2b#1243), so the upload
@@ -139,7 +146,8 @@ export async function uploadFile(
fileName,
fileContextPath,
ignorePatterns,
- resolveSymlinks
+ resolveSymlinks,
+ gzip
)
uploadStream = tar.stream
diff --git a/packages/js-sdk/src/template/consts.ts b/packages/js-sdk/src/template/consts.ts
index b27270e52..a36e8eb8a 100644
--- a/packages/js-sdk/src/template/consts.ts
+++ b/packages/js-sdk/src/template/consts.ts
@@ -33,6 +33,13 @@ export const STACK_TRACE_DEPTH = 3
*/
export const RESOLVE_SYMLINKS = false
+/**
+ * Default setting for whether to gzip files when copying them into the
+ * template. When true, the upload archive is gzipped before being uploaded.
+ * @internal
+ */
+export const GZIP = true
+
/**
* Default per-request timeout (in milliseconds) for the file-upload phase
* (PUT to S3 presigned URL) when the caller hasn't supplied
diff --git a/packages/js-sdk/src/template/index.ts b/packages/js-sdk/src/template/index.ts
index 186e0a312..7e75c92d6 100644
--- a/packages/js-sdk/src/template/index.ts
+++ b/packages/js-sdk/src/template/index.ts
@@ -16,7 +16,7 @@ import {
uploadFile,
waitForBuildFinish,
} from './buildApi'
-import { RESOLVE_SYMLINKS, STACK_TRACE_DEPTH } from './consts'
+import { GZIP, RESOLVE_SYMLINKS, STACK_TRACE_DEPTH } from './consts'
import { parseDockerfile } from './dockerfileParser'
import { LogEntry, LogEntryEnd, LogEntryStart } from './logger'
import { ReadyCmd, waitForFile } from './readycmd'
@@ -570,6 +570,7 @@ export class TemplateBase
user?: string
mode?: number
resolveSymlinks?: boolean
+ gzip?: boolean
}
): TemplateBuilder {
if (runtime === 'browser') {
@@ -598,6 +599,7 @@ export class TemplateBase
force: options?.forceUpload || this.forceNextLayer,
forceUpload: options?.forceUpload,
resolveSymlinks: options?.resolveSymlinks,
+ gzip: options?.gzip,
})
// Collect one stack trace per pushed instruction so build steps stay
@@ -626,6 +628,7 @@ export class TemplateBase
user: item.user,
mode: item.mode,
resolveSymlinks: item.resolveSymlinks,
+ gzip: item.gzip,
})
} catch (error) {
const copyError = error as Error
@@ -1193,6 +1196,7 @@ export class TemplateBase
...readDockerignore(this.fileContextPath.toString()),
],
resolveSymlinks: instruction.resolveSymlinks ?? RESOLVE_SYMLINKS,
+ gzip: instruction.gzip ?? GZIP,
},
stackTrace,
// Forward `requestTimeoutMs` only when the caller set it — we
diff --git a/packages/js-sdk/src/template/types.ts b/packages/js-sdk/src/template/types.ts
index d96570002..ca3594c51 100644
--- a/packages/js-sdk/src/template/types.ts
+++ b/packages/js-sdk/src/template/types.ts
@@ -197,6 +197,7 @@ export type Instruction = {
forceUpload?: true
filesHash?: string
resolveSymlinks?: boolean
+ gzip?: boolean
}
/**
@@ -209,6 +210,7 @@ export type CopyItem = {
user?: string
mode?: number
resolveSymlinks?: boolean
+ gzip?: boolean
}
/**
@@ -412,6 +414,7 @@ export interface TemplateBuilder {
user?: string
mode?: number
resolveSymlinks?: boolean
+ gzip?: boolean
}
): TemplateBuilder
diff --git a/packages/js-sdk/src/template/utils.ts b/packages/js-sdk/src/template/utils.ts
index cd287e9a2..933cdd177 100644
--- a/packages/js-sdk/src/template/utils.ts
+++ b/packages/js-sdk/src/template/utils.ts
@@ -371,13 +371,15 @@ export function padOctal(mode: number): string {
* @param fileContextPath Base directory for resolving file paths
* @param ignorePatterns Ignore patterns to exclude from the archive
* @param resolveSymlinks Whether to follow symbolic links
+ * @param gzip Whether to gzip the archive
* @returns The readable stream and the archive size in bytes
*/
export async function tarFileStream(
fileName: string,
fileContextPath: string,
ignorePatterns: string[],
- resolveSymlinks: boolean
+ resolveSymlinks: boolean,
+ gzip: boolean
): Promise<{ stream: Readable; size: number }> {
const { create } = await dynamicImport<typeof import('tar')>('tar')
// Dynamically import so the browser bundle doesn't pull in node:fs.
@@ -405,7 +407,7 @@ export async function tarFileStream(
try {
await create(
{
- gzip: true,
+ gzip,
cwd: fileContextPath,
follow: resolveSymlinks,
noDirRecurse: true,
diff --git a/packages/js-sdk/tests/template/uploadFile.test.ts b/packages/js-sdk/tests/template/uploadFile.test.ts
index 119301e22..280b959a6 100644
--- a/packages/js-sdk/tests/template/uploadFile.test.ts
+++ b/packages/js-sdk/tests/template/uploadFile.test.ts
@@ -52,6 +52,7 @@ describe('uploadFile transfer encoding', () => {
url: baseUrl,
ignorePatterns: [],
resolveSymlinks: false,
+ gzip: true,
},
undefined
)
diff --git a/packages/js-sdk/tests/template/utils/tarFileStream.test.ts b/packages/js-sdk/tests/template/utils/tarFileStream.test.ts
index 3b86dbbcc..762fc6d93 100644
--- a/packages/js-sdk/tests/template/utils/tarFileStream.test.ts
+++ b/packages/js-sdk/tests/template/utils/tarFileStream.test.ts
@@ -126,7 +126,13 @@ describe('tarFileStream', () => {
await writeFile(join(testDir, 'file1.txt'), 'content1')
await writeFile(join(testDir, 'file2.txt'), 'content2')
- const { stream, size } = await tarFileStream('*.txt', testDir, [], false)
+ const { stream, size } = await tarFileStream(
+ '*.txt',
+ testDir,
+ [],
+ false,
+ true
+ )
expect(size).toBeGreaterThan(0)
const contents = await extractTarContents(stream)
@@ -136,6 +142,39 @@ describe('tarFileStream', () => {
expect(contents.get('file2.txt')?.toString()).toBe('content2')
})
+ test('should create an uncompressed tar when gzip is disabled', async () => {
+ await writeFile(join(testDir, 'file1.txt'), 'content1')
+ await writeFile(join(testDir, 'file2.txt'), 'content2')
+
+ const { stream } = await tarFileStream('*.txt', testDir, [], false, false)
+
+ // Buffer the archive so we can both assert it is not gzipped and extract it
+ const chunks: Buffer[] = []
+ for await (const chunk of stream as unknown as AsyncIterable<Buffer>) {
+ chunks.push(Buffer.from(chunk))
+ }
+ const archive = Buffer.concat(chunks)
+
+ // gzip streams start with the magic bytes 0x1f 0x8b — an uncompressed tar must not
+ expect(archive[0]).not.toBe(0x1f)
+ expect(archive.subarray(0, 2).equals(Buffer.from([0x1f, 0x8b]))).toBe(false)
+
+ // And it should still extract to the original files
+ const tarFile = join(tmpdir(), `tar-uncompressed-${Date.now()}.tar`)
+ await writeFile(tarFile, archive)
+ const extractDir = join(tmpdir(), `tar-uncompressed-extract-${Date.now()}`)
+ await mkdir(extractDir, { recursive: true })
+ await tar.extract({ file: tarFile, cwd: extractDir })
+ expect((await readFile(join(extractDir, 'file1.txt'))).toString()).toBe(
+ 'content1'
+ )
+ expect((await readFile(join(extractDir, 'file2.txt'))).toString()).toBe(
+ 'content2'
+ )
+ await rm(tarFile, { force: true })
+ await rm(extractDir, { recursive: true, force: true })
+ })
+
test('should respect ignore patterns', async () => {
await writeFile(join(testDir, 'file1.txt'), 'content1')
await writeFile(join(testDir, 'file2.txt'), 'content2')
@@ -146,7 +185,8 @@ describe('tarFileStream', () => {
'*.txt',
testDir,
['temp*', 'backup*'],
- false
+ false,
+ true
)
const contents = await extractTarContents(stream)
@@ -165,7 +205,7 @@ describe('tarFileStream', () => {
await writeFile(join(testDir, 'src', 'index.ts'), 'index content')
await writeFile(join(nestedDir, 'Button.tsx'), 'button content')
- const { stream } = await tarFileStream('src', testDir, [], false)
+ const { stream } = await tarFileStream('src', testDir, [], false, true)
const contents = await extractTarContents(stream)
const paths = Array.from(contents.keys())
@@ -187,7 +227,8 @@ describe('tarFileStream', () => {
throw error
}
- const { stream } = await tarFileStream('*.txt', testDir, [], true)
+ // Test with resolveSymlinks=true
+ const { stream } = await tarFileStream('*.txt', testDir, [], true, true)
const contents = await extractTarContents(stream)
expect(contents.get('original.txt')?.toString()).toBe('original content')
@@ -208,7 +249,8 @@ describe('tarFileStream', () => {
throw error
}
- const { stream } = await tarFileStream('*.txt', testDir, [], false)
+ // Test with resolveSymlinks=false
+ const { stream } = await tarFileStream('*.txt', testDir, [], false, true)
const members = await getTarMembers(stream)
expect(members.get('original.txt')?.type).toBe('File')
diff --git a/packages/python-sdk/e2b/template/consts.py b/packages/python-sdk/e2b/template/consts.py
index eb0070671..f40d8382c 100644
--- a/packages/python-sdk/e2b/template/consts.py
+++ b/packages/python-sdk/e2b/template/consts.py
@@ -29,6 +29,12 @@ When False, symlinks are copied as symlinks rather than following them.
"""
RESOLVE_SYMLINKS = False
+"""
+Default setting for whether to gzip files when copying them into the
+template. When True, the upload archive is gzipped before being uploaded.
+"""
+GZIP = True
+
"""
Default timeout (in seconds) for uploading the build-context archive to the
S3 presigned URL. Uploads of large archives can take far longer than the 60s
diff --git a/packages/python-sdk/e2b/template/dockerfile_parser.py b/packages/python-sdk/e2b/template/dockerfile_parser.py
index 434501779..d51bf9e71 100644
--- a/packages/python-sdk/e2b/template/dockerfile_parser.py
+++ b/packages/python-sdk/e2b/template/dockerfile_parser.py
@@ -28,6 +28,7 @@ class DockerfileParserInterface(Protocol):
user: Optional[str] = None,
mode: Optional[int] = None,
resolve_symlinks: Optional[bool] = None,
+ gzip: Optional[bool] = None,
) -> "DockerfileParserInterface":
"""Handle COPY instruction."""
...
diff --git a/packages/python-sdk/e2b/template/main.py b/packages/python-sdk/e2b/template/main.py
index 1928a5918..8b75642ca 100644
--- a/packages/python-sdk/e2b/template/main.py
+++ b/packages/python-sdk/e2b/template/main.py
@@ -46,6 +46,7 @@ class TemplateBuilder:
user: Optional[str] = None,
mode: Optional[int] = None,
resolve_symlinks: Optional[bool] = None,
+ gzip: Optional[bool] = None,
) -> "TemplateBuilder":
"""
Copy files or directories from the local filesystem into the template.
@@ -56,6 +57,7 @@ class TemplateBuilder:
:param user: User and optionally group (user:group) to own the files
:param mode: File permissions in octal format (e.g., 0o755)
:param resolve_symlinks: Whether to resolve symlinks
+ :param gzip: Whether to gzip the files before upload (default: True)
:return: `TemplateBuilder` class
@@ -90,6 +92,7 @@ class TemplateBuilder:
"force": force_upload or self._template._force_next_layer,
"forceUpload": force_upload,
"resolveSymlinks": resolve_symlinks,
+ "gzip": gzip,
}
self._template._instructions.append(instruction)
@@ -131,6 +134,7 @@ class TemplateBuilder:
item.get("user"),
item.get("mode"),
item.get("resolveSymlinks"),
+ item.get("gzip"),
)
except Exception as error:
# Re-raise the error with the captured stack trace
@@ -1278,6 +1282,7 @@ class TemplateBase:
"force": instruction["force"],
"forceUpload": instruction.get("forceUpload"),
"resolveSymlinks": instruction.get("resolveSymlinks"),
+ "gzip": instruction.get("gzip"),
}
if instruction["type"] == InstructionType.COPY:
diff --git a/packages/python-sdk/e2b/template/types.py b/packages/python-sdk/e2b/template/types.py
index 05b6307d4..3f8c0d051 100644
--- a/packages/python-sdk/e2b/template/types.py
+++ b/packages/python-sdk/e2b/template/types.py
@@ -113,6 +113,7 @@ class CopyItem(TypedDict):
user: NotRequired[Optional[str]]
mode: NotRequired[Optional[int]]
resolveSymlinks: NotRequired[Optional[bool]]
+ gzip: NotRequired[Optional[bool]]
class Instruction(TypedDict):
@@ -126,6 +127,7 @@ class Instruction(TypedDict):
forceUpload: NotRequired[Optional[Literal[True]]]
filesHash: NotRequired[Optional[str]]
resolveSymlinks: NotRequired[Optional[bool]]
+ gzip: NotRequired[Optional[bool]]
class GenericDockerRegistry(TypedDict):
diff --git a/packages/python-sdk/e2b/template/utils.py b/packages/python-sdk/e2b/template/utils.py
index cdfc62547..09a7cfc17 100644
--- a/packages/python-sdk/e2b/template/utils.py
+++ b/packages/python-sdk/e2b/template/utils.py
@@ -259,6 +259,7 @@ def tar_file_stream(
file_context_path: str,
ignore_patterns: List[str],
resolve_symlinks: bool,
+ gzip: bool,
) -> IO[bytes]:
"""
Create a tar archive of files matching a pattern in a temporary file.
@@ -270,6 +271,7 @@ def tar_file_stream(
:param file_context_path: Base directory for resolving file paths
:param ignore_patterns: Ignore patterns
:param resolve_symlinks: Whether to resolve symbolic links
+ :param gzip: Whether to gzip the archive
:return: Binary file object positioned at the start of the archive
"""
@@ -277,7 +279,7 @@ def tar_file_stream(
try:
with tarfile.open(
fileobj=tar_file,
- mode="w:gz",
+ mode="w:gz" if gzip else "w",
dereference=resolve_symlinks,
) as tar:
files = get_all_files_in_path(
diff --git a/packages/python-sdk/e2b/template_async/build_api.py b/packages/python-sdk/e2b/template_async/build_api.py
index d306cea17..c9209fa5d 100644
--- a/packages/python-sdk/e2b/template_async/build_api.py
+++ b/packages/python-sdk/e2b/template_async/build_api.py
@@ -107,6 +107,7 @@ async def upload_file(
url: str,
ignore_patterns: List[str],
resolve_symlinks: bool,
+ gzip: bool,
stack_trace: Optional[TracebackType],
request_timeout: Optional[float] = None,
):
@@ -119,7 +120,7 @@ async def upload_file(
)
try:
tar_file = tar_file_stream(
- file_name, context_path, ignore_patterns, resolve_symlinks
+ file_name, context_path, ignore_patterns, resolve_symlinks, gzip
)
try:
size = os.fstat(tar_file.fileno()).st_size
diff --git a/packages/python-sdk/e2b/template_async/main.py b/packages/python-sdk/e2b/template_async/main.py
index 78d80c94c..5c0a2c050 100644
--- a/packages/python-sdk/e2b/template_async/main.py
+++ b/packages/python-sdk/e2b/template_async/main.py
@@ -5,7 +5,7 @@ from typing_extensions import Unpack
from e2b.api.client.client import AuthenticatedClient
from e2b.connection_config import ApiParams, ConnectionConfig
-from e2b.template.consts import RESOLVE_SYMLINKS
+from e2b.template.consts import GZIP, RESOLVE_SYMLINKS
from e2b.template.logger import LogEntry, LogEntryEnd, LogEntryStart
from e2b.template.main import TemplateBase, TemplateClass
from e2b.template.types import BuildInfo, InstructionType, TemplateTag, TemplateTagInfo
@@ -101,7 +101,12 @@ class AsyncTemplate(TemplateBase):
src = args[0] if len(args) > 0 else None
force_upload = file_upload.get("forceUpload")
files_hash = file_upload.get("filesHash", None)
- resolve_symlinks = file_upload.get("resolveSymlinks", RESOLVE_SYMLINKS)
+ resolve_symlinks = file_upload.get("resolveSymlinks")
+ if resolve_symlinks is None:
+ resolve_symlinks = RESOLVE_SYMLINKS
+ gzip = file_upload.get("gzip")
+ if gzip is None:
+ gzip = GZIP
if src is None or files_hash is None:
raise ValueError("Source path and files hash are required")
@@ -127,6 +132,7 @@ class AsyncTemplate(TemplateBase):
*read_dockerignore(template._template._file_context_path),
],
resolve_symlinks,
+ gzip,
stack_trace,
request_timeout=request_timeout,
)
diff --git a/packages/python-sdk/e2b/template_sync/build_api.py b/packages/python-sdk/e2b/template_sync/build_api.py
index 243fc81dc..e838d8788 100644
--- a/packages/python-sdk/e2b/template_sync/build_api.py
+++ b/packages/python-sdk/e2b/template_sync/build_api.py
@@ -105,6 +105,7 @@ def upload_file(
url: str,
ignore_patterns: List[str],
resolve_symlinks: bool,
+ gzip: bool,
stack_trace: Optional[TracebackType],
request_timeout: Optional[float] = None,
):
@@ -117,7 +118,7 @@ def upload_file(
)
try:
tar_file = tar_file_stream(
- file_name, context_path, ignore_patterns, resolve_symlinks
+ file_name, context_path, ignore_patterns, resolve_symlinks, gzip
)
try:
with httpx.Client(
diff --git a/packages/python-sdk/e2b/template_sync/main.py b/packages/python-sdk/e2b/template_sync/main.py
index 94414de2f..e86d3e7e9 100644
--- a/packages/python-sdk/e2b/template_sync/main.py
+++ b/packages/python-sdk/e2b/template_sync/main.py
@@ -7,7 +7,7 @@ from e2b.api.client.client import AuthenticatedClient
from e2b.connection_config import ApiParams, ConnectionConfig
from e2b.api.client_sync import get_api_client
-from e2b.template.consts import RESOLVE_SYMLINKS
+from e2b.template.consts import GZIP, RESOLVE_SYMLINKS
from e2b.template.logger import LogEntry, LogEntryEnd, LogEntryStart
from e2b.template.main import TemplateBase, TemplateClass
from e2b.template.types import BuildInfo, InstructionType, TemplateTag, TemplateTagInfo
@@ -101,7 +101,12 @@ class Template(TemplateBase):
src = args[0] if len(args) > 0 else None
force_upload = file_upload.get("forceUpload")
files_hash = file_upload.get("filesHash", None)
- resolve_symlinks = file_upload.get("resolveSymlinks", RESOLVE_SYMLINKS)
+ resolve_symlinks = file_upload.get("resolveSymlinks")
+ if resolve_symlinks is None:
+ resolve_symlinks = RESOLVE_SYMLINKS
+ gzip = file_upload.get("gzip")
+ if gzip is None:
+ gzip = GZIP
if src is None or files_hash is None:
raise ValueError("Source path and files hash are required")
@@ -127,6 +132,7 @@ class Template(TemplateBase):
*read_dockerignore(template._template._file_context_path),
],
resolve_symlinks,
+ gzip,
stack_trace,
request_timeout=request_timeout,
)
diff --git a/packages/python-sdk/tests/async/template_async/test_upload_file.py b/packages/python-sdk/tests/async/template_async/test_upload_file.py
index d4f4b0414..4b61e7c57 100644
--- a/packages/python-sdk/tests/async/template_async/test_upload_file.py
+++ b/packages/python-sdk/tests/async/template_async/test_upload_file.py
@@ -63,6 +63,7 @@ async def test_upload_file_sets_content_length_and_no_chunked_encoding(tmp_path)
url=url,
ignore_patterns=[],
resolve_symlinks=False,
+ gzip=True,
stack_trace=None,
)
finally:
@@ -112,6 +113,7 @@ async def _capture_upload_timeout(tmp_path, request_timeout=None):
url=url,
ignore_patterns=[],
resolve_symlinks=False,
+ gzip=True,
stack_trace=None,
**kwargs,
)
@@ -184,6 +186,7 @@ async def test_upload_file_ignores_post_upload_close_failure(tmp_path):
url=url,
ignore_patterns=[],
resolve_symlinks=False,
+ gzip=True,
stack_trace=None,
)
finally:
diff --git a/packages/python-sdk/tests/shared/template/utils/test_tar_file_stream.py b/packages/python-sdk/tests/shared/template/utils/test_tar_file_stream.py
index b274e4955..9f6b4fd9b 100644
--- a/packages/python-sdk/tests/shared/template/utils/test_tar_file_stream.py
+++ b/packages/python-sdk/tests/shared/template/utils/test_tar_file_stream.py
@@ -18,7 +18,8 @@ class TestTarFileStream:
"""Extract tar contents into a dictionary mapping paths to file contents."""
tar_buffer.seek(0)
contents = {}
- with tarfile.open(fileobj=tar_buffer, mode="r:gz") as tar:
+ # "r:*" auto-detects compressed vs. uncompressed archives
+ with tarfile.open(fileobj=tar_buffer, mode="r:*") as tar:
for member in tar.getmembers():
if member.isfile():
file_obj = tar.extractfile(member)
@@ -39,7 +40,7 @@ class TestTarFileStream:
with open(file2_path, "w") as f:
f.write("content2")
- tar_buffer = tar_file_stream("*.txt", test_dir, [], False)
+ tar_buffer = tar_file_stream("*.txt", test_dir, [], False, True)
contents = self._extract_tar_contents(tar_buffer)
assert len(contents) == 2
@@ -48,6 +49,27 @@ class TestTarFileStream:
assert contents["file1.txt"] == b"content1"
assert contents["file2.txt"] == b"content2"
+ def test_should_create_uncompressed_tar_when_gzip_disabled(self, test_dir):
+ """Test that function creates an uncompressed tar when gzip=False."""
+ file1_path = os.path.join(test_dir, "file1.txt")
+ file2_path = os.path.join(test_dir, "file2.txt")
+
+ with open(file1_path, "w") as f:
+ f.write("content1")
+ with open(file2_path, "w") as f:
+ f.write("content2")
+
+ tar_buffer = tar_file_stream("*.txt", test_dir, [], False, False)
+
+ # gzip streams start with the magic bytes 0x1f 0x8b — a plain tar must not
+ tar_buffer.seek(0)
+ assert tar_buffer.read(2) != b"\x1f\x8b"
+
+ # The archive must still be readable and contain the original files
+ contents = self._extract_tar_contents(tar_buffer)
+ assert contents["file1.txt"] == b"content1"
+ assert contents["file2.txt"] == b"content2"
+
def test_should_respect_ignore_patterns(self, test_dir):
"""Test that function respects ignore patterns."""
# Create test files
@@ -60,7 +82,9 @@ class TestTarFileStream:
with open(os.path.join(test_dir, "backup.txt"), "w") as f:
f.write("backup content")
- tar_buffer = tar_file_stream("*.txt", test_dir, ["temp*", "backup*"], False)
+ tar_buffer = tar_file_stream(
+ "*.txt", test_dir, ["temp*", "backup*"], False, True
+ )
contents = self._extract_tar_contents(tar_buffer)
assert len(contents) == 2
@@ -82,7 +106,7 @@ class TestTarFileStream:
with open(os.path.join(nested_dir, "Button.tsx"), "w") as f:
f.write("button content")
- tar_buffer = tar_file_stream("src", test_dir, [], False)
+ tar_buffer = tar_file_stream("src", test_dir, [], False, True)
contents = self._extract_tar_contents(tar_buffer)
# Should include the directory and files
@@ -104,7 +128,7 @@ class TestTarFileStream:
os.symlink("original.txt", symlink_path)
# Test with resolve_symlinks=True
- tar_buffer = tar_file_stream("*.txt", test_dir, [], True)
+ tar_buffer = tar_file_stream("*.txt", test_dir, [], True, True)
contents = self._extract_tar_contents(tar_buffer)
# Both files should be in tar
@@ -129,7 +153,7 @@ class TestTarFileStream:
os.symlink("original.txt", symlink_path)
# Test with resolve_symlinks=False
- tar_buffer = tar_file_stream("*.txt", test_dir, [], False)
+ tar_buffer = tar_file_stream("*.txt", test_dir, [], False, True)
tar_buffer.seek(0)
with tarfile.open(fileobj=tar_buffer, mode="r:gz") as tar:
diff --git a/packages/python-sdk/tests/sync/template_sync/test_upload_file.py b/packages/python-sdk/tests/sync/template_sync/test_upload_file.py
index e2dd9a83a..74b65fa8c 100644
--- a/packages/python-sdk/tests/sync/template_sync/test_upload_file.py
+++ b/packages/python-sdk/tests/sync/template_sync/test_upload_file.py
@@ -59,6 +59,7 @@ def test_upload_file_sets_content_length_and_no_chunked_encoding(tmp_path):
url=url,
ignore_patterns=[],
resolve_symlinks=False,
+ gzip=True,
stack_trace=None,
)
finally:
@@ -108,6 +109,7 @@ def _capture_upload_timeout(tmp_path, request_timeout=None):
url=url,
ignore_patterns=[],
resolve_symlinks=False,
+ gzip=True,
stack_trace=None,
**kwargs,
)
@@ -180,6 +182,7 @@ def test_upload_file_ignores_post_upload_close_failure(tmp_path):
url=url,
ignore_patterns=[],
resolve_symlinks=False,
+ gzip=True,
stack_trace=None,
)
finally: