Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Fix line splitter (#62)
Browse files Browse the repository at this point in the history
Replace use of LineSplitter with wrapper that correctly implements
the Converter<String, List<String>> interface.
  • Loading branch information
leafpetersen authored and tvolkert committed Nov 22, 2017
1 parent ec7dfdb commit 12156a5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#### 2.3.5

* Fix internal use of a cast which fails on Dart 2.0 .

#### 2.3.4

* Bumped maximum Dart SDK version to 2.0.0-dev.infinity
Expand Down
26 changes: 26 additions & 0 deletions lib/src/backends/record_replay/codecs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,32 @@ class _GenericEncoder extends Converter<dynamic, dynamic> {
}
}

/// A trivial conversion turning a Sink<List<String>> into a
/// Sink<String>
class _StringSinkWrapper implements Sink<String> {
final Sink<List<String>> _sink;
_StringSinkWrapper(this._sink);
@override
void add(String s) => _sink.add(<String>[s]);
@override
void close() => _sink.close();
}

/// An Converter version of the dart:convert LineSplitter (which in
/// 2.0 no longer implements the Converter interface)
class LineSplitterConverter extends Converter<String, List<String>> {
final LineSplitter _splitter = const LineSplitter();

/// Creates a new [LineSplitterConverter]
const LineSplitterConverter();

@override
List<String> convert(String input) => _splitter.convert(input);
@override
StringConversionSink startChunkedConversion(Sink<List<String>> sink) =>
_splitter.startChunkedConversion(new _StringSinkWrapper(sink));
}

/// Converter that leaves an object untouched.
class Passthrough<T> extends Converter<T, T> {
/// Creates a new [Passthrough].
Expand Down
2 changes: 1 addition & 1 deletion lib/src/backends/record_replay/replay_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ReplayFile extends ReplayFileSystemEntity implements File {
Converter<String, RandomAccessFile> reviveRandomAccessFile =
new ReviveRandomAccessFile(fileSystem);
Converter<String, List<String>> lineSplitter =
const LineSplitter() as Converter<String, List<String>>;
const LineSplitterConverter();
Converter<String, List<String>> blobToLines =
blobToString.fuse(lineSplitter);
Converter<String, Stream<List<int>>> blobToByteStream = blobToBytes
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: file
version: 2.3.4
version: 2.3.5
authors:
- Matan Lurey <[email protected]>
- Yegor Jbanov <[email protected]>
Expand Down

0 comments on commit 12156a5

Please sign in to comment.