alexrintt / shared-storage

Flutter plugin to work with Android external storage.
http://alexrintt.io/shared-storage/
MIT License
52 stars 26 forks source link

Add request for file writing #122

Closed 250king closed 1 year ago

250king commented 1 year ago

A Feature request

I need to usa the setPosition methd to modify some file. But after I refer your API document, I can't find any thing about this. So I give some suggestion here. If writeToFileAsBytes supports setPosition, it will be better.

alexrintt commented 1 year ago

what is the use-case? Do you want to set the position (cursor) for modifying a file in a certain index? Do you have any examples of this setPosition method in other library or project?

250king commented 1 year ago

I show a example from my code. Maybe you can know my meaning.

static void write(File file, String origin, String replace, int position) {
    try {
      final io = file.openSync(mode: FileMode.append);
      const compare = ListEquality();
      final length = origin.length;
      io.setPositionSync(position);
      final raw = io.readSync(length);
      if (!compare.equals(raw, utf8.encode(replace))) {
        if (compare.equals(raw, utf8.encode(origin))) {
          io.setPositionSync(position);
          io.writeFromSync(utf8.encode(replace));
        }
      }
      io.closeSync();
    }
    // ignore: empty_catches, empty_statements
    catch (e) {}
  }