addFileToTarEntry static method

void addFileToTarEntry(
  1. File file,
  2. String basePath,
  3. StreamController<TarEntry> controller,
  4. StringBuffer? logBuffer,
)

Adds a single file to the tar archive controller.

This method can be called externally to dynamically add files to an archive when using an external StreamController<TarEntry>.

Parameters:

  • file: The file to add to the archive.
  • basePath: The base path for computing relative paths.
  • controller: The tar entry stream controller.
  • logBuffer: Optional buffer for logging.

Implementation

static void addFileToTarEntry(
  File file,
  String basePath,
  StreamController<TarEntry> controller,
  StringBuffer? logBuffer,
) {
  final relativePath = p.relative(file.path, from: basePath);
  logBuffer?.writeln('Adding: $relativePath');

  controller.add(
    TarEntry(
      TarHeader(
        name: relativePath,
        size: file.lengthSync(),
        mode: int.parse('644', radix: 8),
        modified: file.lastModifiedSync(),
      ),
      file.openRead(),
    ),
  );
}