读取文件
你可以使用files.read() 方法从 Sandbox 文件系统读取文件。
from ppio_sandbox import PPIO
ppio = PPIO()
sandbox = ppio.sandbox.create()
file_path_in_sandbox = '/tmp/test-file'
sandbox.files.write(file_path_in_sandbox, 'test-file-content')
file_content = sandbox.files.read(file_path_in_sandbox)
print(file_content)
sandbox.kill()
import { PPIO } from 'ppio-sandbox'
const ppio = new PPIO()
const sandbox = await ppio.sandbox.create()
// 在 Sandbox 中创建测试文件
const filePathInSandbox = '/tmp/test-file'
await sandbox.files.write(filePathInSandbox, 'test-file-content')
const fileContent = await sandbox.files.read(filePathInSandbox)
console.log(fileContent)
await sandbox.kill()
写入单个文件
你可以使用files.write() 方法向 Sandbox 文件系统写入单个文件。
from ppio_sandbox import PPIO
ppio = PPIO()
sandbox = ppio.sandbox.create()
file_path_in_sandbox = '/tmp/test-file'
result = sandbox.files.write(file_path_in_sandbox, 'test-file-content')
print(result)
sandbox.kill()
import { PPIO } from 'ppio-sandbox'
const ppio = new PPIO()
const sandbox = await ppio.sandbox.create()
const filePathInSandbox = '/tmp/test-file'
const result = await sandbox.files.write(filePathInSandbox, 'test-file-content')
console.log(result)
await sandbox.kill()
写入多个文件
你也可以使用files.write() 方法向 Sandbox 文件系统写入多个文件。
from ppio_sandbox import PPIO
ppio = PPIO()
sandbox = ppio.sandbox.create()
result = sandbox.files.write_files([
{"path": "/tmp/test-file-1", "data": "file content 1"},
{"path": "/tmp/test-file-2", "data": "file content 2"},
])
print(result)
sandbox.kill()
import { PPIO } from 'ppio-sandbox'
const ppio = new PPIO()
const sandbox = await ppio.sandbox.create()
const result = await sandbox.files.write([
{ path: '/tmp/test-file-1', data: 'file content 1' },
{ path: '/tmp/test-file-2', data: 'file content 2' },
])
console.log(result)
await sandbox.kill()