Skip to content

armgit / E2B

Public Imported from GitHub
0

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

559 B
Raw Blame
import * as fs from 'fs'
import * as path from 'path'

/**
 * Write content to a file, creating directories if needed
 */
export async function writeFileContent(
  filePath: string,
  content: string
): Promise<void> {
  if (fs.existsSync(filePath)) {
    throw new Error(
      `File ${filePath} already exists. Aborting to avoid overwrite.`
    )
  }

  // Ensure directory exists
  const dir = path.dirname(filePath)
  if (!fs.existsSync(dir)) {
    await fs.promises.mkdir(dir, { recursive: true })
  }

  await fs.promises.writeFile(filePath, content)
}