Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringConversionSink.asStringSink() and asUtf8Sink() don't invalidate this #29353

Open
sgrekhov opened this issue Apr 14, 2017 · 0 comments
Open
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. core-a library-convert type-documentation A request to add or improve documentation

Comments

@sgrekhov
Copy link
Contributor

sgrekhov commented Apr 14, 2017

Please see StringConversionSink.asStringSink() documentation at https://api.dartlang.org/stable/1.22.1/dart-convert/StringConversionSink/asStringSink.html

ClosableStringSink asStringSink()
Returns this as a ClosableStringSink.

If used, this method must be the first and only call to this. It invalidates this. All further operations must be performed on the result.

Now look at the following code.

import "dart:convert";
main() {
  var outSink = new ByteConversionSink.withCallback((accumulated) {
    print(accumulated);
  });

  StringConversionSink inSink = UTF8.encoder.startChunkedConversion(outSink);
  inSink.add("1");

  ClosableStringSink css = inSink.asStringSink();
  css.write("2");
  inSink.add("3");
  css.close(); // prints [49, 50, 51]. It's encoded string "123"
  inSink.add("4");
  inSink.close(); // prints [49, 50, 51, 52]. It's encoded string "1234"
  inSink.add("5");
  inSink.close(); // prints [49, 50, 51, 52, 53]. It's encoded string "12345"
}

I don't see that asStringSink() invalidates anything.

The same is true for StringConversionSink.asUtf8Sink()

import "dart:convert";
main() {
  var outSink = new ByteConversionSink.withCallback((accumulated) {
    print(accumulated);
  });

  StringConversionSink inSink = UTF8.encoder.startChunkedConversion(outSink);
  inSink.add("1");

  ByteConversionSink bcs = inSink.asUtf8Sink(false);
  bcs.add([50]); // [50] is utf-8 encoding of 2
  inSink.add("3");
  bcs.close(); // prints [49, 50, 51]. It's encoded string "123"
  inSink.add("4");
  inSink.close(); // prints [49, 50, 51, 52]. It's encoded string "1234"
  inSink.add("5");
  inSink.close(); // prints [49, 50, 51, 52, 53]. It's encoded string "12345"
}
@sgrekhov sgrekhov changed the title StringConversionSink.asStringSink() doesn't invalidate this StringConversionSink.asStringSink() and asUtf8Sink() don't invalidate this Apr 14, 2017
@vsmenon vsmenon added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-convert labels Apr 17, 2017
@lrhn lrhn added the type-documentation A request to add or improve documentation label Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. core-a library-convert type-documentation A request to add or improve documentation
Projects
None yet
Development

No branches or pull requests

4 participants