createTempFile static method

Future<String> createTempFile(
  1. String name, [
  2. String content = ''
])

Creates a temporary file with the specified name and content. The file will be stored in the system's temporary directory with proper permissions.

Returns the full path to the created temporary file.

Implementation

static Future<String> createTempFile(String name, [String content = '']) async {
  try {
    final tempDir = await Directory.systemTemp.createTemp('https_');
    final filePath = '${tempDir.path}/$name';

    // Create the file with proper permissions (readable and writable)
    final file = File(filePath);
    await file.create(recursive: true);
    await file.writeAsString(content);

    // Track the temporary file
    _tempFiles[name] = filePath;

    return filePath;
  } catch (e) {
    Error.throwWithStackTrace(
      HTTPSException(
        message: 'Failed to create temporary file $name: ${e.toString()}',
        originalError: e,
      ),
      StackTrace.current,
    );
  }
}