Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a "fake" dart:io File from in-memory bytes?

Tags:

flutter

dart

I have the in-memory bytes of a "blob", but the API that I want to process this "blob" with only accepts dart:io File objects.

Is there a way to create a "fake" dart:io File , simply wrapping my in-memory bytes, so that I can pass this "fake" File to my API?

Assume that a file system doesn't exist, and assume that I can't write the in-memory bytes to a "real" file.

Thanks!

like image 376
Seth Ladd Avatar asked Dec 18 '17 04:12

Seth Ladd


People also ask

How do you create a text file in dart?

Write to a file To write a string to a file, use the writeAsString method: import 'dart:io'; void main() async { final filename = 'file. txt'; var file = await File(filename). writeAsString('some content'); // Do something with the file. }


Video Answer


1 Answers

You can create a memory-file using MemoryFileSystem from the package file:

Example:

File file = MemoryFileSystem().file('test.dart')
  ..writeAsBytesSync(blobBytes);
like image 164
Hugo Passos Avatar answered Oct 22 '22 09:10

Hugo Passos