Skip to content

Commit b9bddff

Browse files
committed
bugbot
1 parent aed23cd commit b9bddff

8 files changed

Lines changed: 39 additions & 53 deletions

File tree

packages/js-sdk/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ export type {
8989
VolumeInfo,
9090
VolumeEntryStat,
9191
VolumeFileType,
92-
VolumeWriteInfo,
9392
VolumeMetadataOptions,
9493
VolumeWriteOptions,
9594
VolumeRemoveOptions,

packages/js-sdk/src/volume/index.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ export class Volume {
4747
*
4848
* @param volumeId volume ID.
4949
*/
50-
constructor(volumeId: string, name?: string) {
50+
constructor(volumeId: string, name: string) {
5151
this.volumeId = volumeId
52-
this.name = name ?? volumeId
52+
this.name = name
5353
}
5454

5555
/**
@@ -511,6 +511,10 @@ export class Volume {
511511
return new Uint8Array(res.data as ArrayBuffer)
512512
}
513513

514+
if (format === 'text') {
515+
return res.data?.toString() ?? ''
516+
}
517+
514518
return res.data
515519
}
516520

@@ -533,14 +537,12 @@ export class Volume {
533537
data: string | ArrayBuffer | Blob | ReadableStream<Uint8Array>,
534538
options?: VolumeWriteOptions,
535539
opts?: VolumeApiOpts
536-
): Promise<void> {
540+
): Promise<VolumeEntryStat> {
537541
const config = new ConnectionConfig(opts)
538542
const client = new ApiClient(config)
539543

540-
// Convert data to Blob using the same utility as sandbox.files.write
541544
const blob = await toBlob(data)
542545

543-
// Use bodySerializer to send binary data with correct Content-Type header
544546
const res = await client.api.PUT('/volumes/{volumeID}/file', {
545547
params: {
546548
path: {
@@ -570,6 +572,14 @@ export class Volume {
570572
if (err) {
571573
throw err
572574
}
575+
576+
if (!res.data) {
577+
throw new Error('Response data is missing')
578+
}
579+
580+
return convertVolumeEntryStat(
581+
res.data as components['schemas']['VolumeEntryStat']
582+
)
573583
}
574584

575585
/**
@@ -628,7 +638,6 @@ export class Volume {
628638
export type {
629639
VolumeInfo,
630640
VolumeFileType,
631-
VolumeWriteInfo,
632641
VolumeEntryStat,
633642
VolumeMetadataOptions,
634643
VolumeWriteOptions,

packages/js-sdk/src/volume/types.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,6 @@ export type VolumeInfo = {
2121
*/
2222
export type VolumeFileType = components['schemas']['VolumeEntryStat']['type']
2323

24-
/**
25-
* Information about a written file.
26-
*/
27-
export type VolumeWriteInfo = {
28-
/**
29-
* Name of the filesystem object.
30-
*/
31-
name: string
32-
33-
/**
34-
* Type of the filesystem object.
35-
*/
36-
type?: VolumeFileType
37-
38-
/**
39-
* Path to the filesystem object.
40-
*/
41-
path: string
42-
}
43-
4424
/**
4525
* Volume entry stat with dates converted to Date objects.
4626
*/

packages/js-sdk/tests/volume/file.test.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ describe('Volume File Operations', () => {
88
const path = '/test.txt'
99
const content = 'Hello, World!'
1010

11-
await volume.writeFile(path, content)
12-
const readContent = await volume.readFile(path, { format: 'text' })
11+
const stat = await volume.writeFile(path, content)
12+
expect(stat.name).toBe('test.txt')
13+
expect(stat.type).toBe('file')
14+
expect(stat.path).toBe(path)
15+
expect(stat.mtime).toBeInstanceOf(Date)
16+
expect(stat.ctime).toBeInstanceOf(Date)
1317

18+
const readContent = await volume.readFile(path, { format: 'text' })
1419
expect(readContent).toBe(content)
1520
})
1621

@@ -73,17 +78,16 @@ describe('Volume File Operations', () => {
7378
const path = '/metadata.txt'
7479
const content = 'File with metadata'
7580

76-
await volume.writeFile(path, content, {
81+
const stat = await volume.writeFile(path, content, {
7782
uid: 1000,
7883
gid: 1000,
7984
mode: 0o644,
8085
})
8186

82-
const entryInfo = await volume.getInfo(path)
83-
expect(entryInfo.type).toBe('file')
84-
expect(entryInfo.uid).toBe(1000)
85-
expect(entryInfo.gid).toBe(1000)
86-
expect(entryInfo.mode).toBe(0o644)
87+
expect(stat.type).toBe('file')
88+
expect(stat.uid).toBe(1000)
89+
expect(stat.gid).toBe(1000)
90+
expect(stat.mode).toBe(0o644)
8791
}
8892
)
8993

packages/python-sdk/e2b/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
VolumeInfo,
121121
VolumeEntryStat,
122122
VolumeFileType,
123-
VolumeWriteInfo,
124123
VolumeMetadataOptions,
125124
VolumeWriteOptions,
126125
VolumeRemoveOptions,
@@ -222,7 +221,6 @@
222221
"VolumeInfo",
223222
"VolumeEntryStat",
224223
"VolumeFileType",
225-
"VolumeWriteInfo",
226224
"VolumeMetadataOptions",
227225
"VolumeWriteOptions",
228226
"VolumeRemoveOptions",

packages/python-sdk/e2b/volume/types.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,6 @@ class VolumeEntryStat:
4444
"""Target path for symlinks."""
4545

4646

47-
class VolumeWriteInfo(TypedDict, total=False):
48-
"""Information about a written file."""
49-
50-
name: str
51-
"""Name of the filesystem object."""
52-
type: Optional[VolumeFileType]
53-
"""Type of the filesystem object."""
54-
path: str
55-
"""Path to the filesystem object."""
56-
57-
5847
class VolumeMetadataOptions(TypedDict, total=False):
5948
"""Options for updating file metadata."""
6049

@@ -82,7 +71,6 @@ class VolumeRemoveOptions(TypedDict, total=False):
8271

8372
__all__ = [
8473
"VolumeInfo",
85-
"VolumeWriteInfo",
8674
"VolumeEntryStat",
8775
"VolumeFileType",
8876
"VolumeMetadataOptions",

packages/python-sdk/e2b/volume/volume_async.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ async def write_file(
468468
mode: Optional[int] = None,
469469
force: Optional[bool] = None,
470470
**opts: Unpack[ApiParams],
471-
) -> None:
471+
) -> VolumeEntryStat:
472472
"""
473473
Write content to a file.
474474
@@ -482,11 +482,12 @@ async def write_file(
482482
:param mode: Mode of the created file
483483
:param force: Force overwrite of an existing file
484484
:param opts: Connection options
485+
486+
:return: Information about the written file
485487
"""
486488
config = ConnectionConfig(**opts)
487489
api_client = get_api_client(config)
488490

489-
# Convert data to bytes
490491
if isinstance(data, str):
491492
data_bytes = data.encode("utf-8")
492493
elif isinstance(data, bytes):
@@ -533,6 +534,9 @@ async def write_file(
533534
if err:
534535
raise err
535536

537+
parsed = VolumeEntryStatApi.from_dict(response.json())
538+
return _convert_volume_entry_stat(parsed)
539+
536540
async def remove(
537541
self,
538542
path: str,

packages/python-sdk/e2b/volume/volume_sync.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ def write_file(
466466
mode: Optional[int] = None,
467467
force: Optional[bool] = None,
468468
**opts: Unpack[ApiParams],
469-
) -> None:
469+
) -> VolumeEntryStat:
470470
"""
471471
Write content to a file.
472472
@@ -480,11 +480,12 @@ def write_file(
480480
:param mode: Mode of the created file
481481
:param force: Force overwrite of an existing file
482482
:param opts: Connection options
483+
484+
:return: Information about the written file
483485
"""
484486
config = ConnectionConfig(**opts)
485487
api_client = get_api_client(config)
486488

487-
# Convert data to bytes
488489
if isinstance(data, str):
489490
data_bytes = data.encode("utf-8")
490491
elif isinstance(data, bytes):
@@ -531,6 +532,9 @@ def write_file(
531532
if err:
532533
raise err
533534

535+
parsed = VolumeEntryStatApi.from_dict(response.json())
536+
return _convert_volume_entry_stat(parsed)
537+
534538
def remove(
535539
self,
536540
path: str,

0 commit comments

Comments
 (0)