Skip to content

ClosableStringSink.close() doesn't close StringSink #29354

Open
@sgrekhov

Description

@sgrekhov

See https://api.dartlang.org/stable/1.22.1/dart-convert/ClosableStringSink/close.html

void close()
Closes this and flushes any outstanding data.

In fact this method does flush but doesn't close the sink

import "dart:convert";
main() {
  StringBuffer stringSink = new StringBuffer();
  stringSink.write("0:");

  ClosableStringSink sink =
  new ClosableStringSink.fromStringSink(stringSink, () {
    stringSink.write(":closed");
  });
  sink.write("1");
  print(stringSink.toString()); // prints 0:1
  sink.close();
  print(stringSink.toString()); // prints 0:1:closed
  sink.write(":2");
  sink.close();
  print(stringSink.toString()); // prints 0:1:closed:2:closed
}

As you can see close() can be called several times. If the current behaviour is correct, and close() should only call onClose, then flush() is more suitable name for this method than close().

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.core-alibrary-converttype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions