slow_file_system 1.0.0 copy "slow_file_system: ^1.0.0" to clipboard
slow_file_system: ^1.0.0 copied to clipboard

Simulate slow file systems by wrapping package:file with delayed I/O operations and delayed returned file objects.

example/slow_file_system_example.dart

import 'dart:io' as io;

import 'package:file/memory.dart';
import 'package:slow_file_system/slow_file_system.dart';

Future<void> main() async {
  final memoryFs = MemoryFileSystem();
  final fs = SlowFileSystem(memoryFs, const Duration(milliseconds: 500));

  final directory = await fs.directory('/tmp').create();
  final file = directory.childFile('note.txt');

  final stopwatch = Stopwatch()..start();
  await file.writeAsString('hello');
  print('writeAsString took ${stopwatch.elapsedMilliseconds} ms');

  stopwatch
    ..reset()
    ..start();
  print('basename is ${file.basename}');
  print('basename lookup took ${stopwatch.elapsedMicroseconds} us');

  stopwatch
    ..reset()
    ..start();
  final sink = file.openWrite(mode: io.FileMode.append);
  sink.writeln('more data');
  await sink.close();
  print('openWrite + write + close took ${stopwatch.elapsedMilliseconds} ms');
}
1
likes
160
points
35
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Simulate slow file systems by wrapping package:file with delayed I/O operations and delayed returned file objects.

Repository (GitHub)
View/report issues

Topics

#file-system #testing #latency

License

BSD-3-Clause (license)

Dependencies

file, path

More

Packages that depend on slow_file_system