Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(967)

Issue 9452014: Implement File.{readAsBytes, readAsText, readAsLines}. (Closed)

Created:
8 years, 10 months ago by Mads Ager (google)
Modified:
8 years, 10 months ago
Reviewers:
Søren Gjesse
CC:
reviews_dartlang.org
Visibility:
Public.

Description

Implement File.{readAsBytes, readAsText, readAsLines}. Convenience methods to use if all you care about is getting the entire contents of a file. R=sgjesse@google.com BUG=1579 TEST=standalone/FileTest Committed: https://code.google.com/p/dart/source/detail?r=4568

Patch Set 1 #

Total comments: 6

Patch Set 2 : Address comments. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+334 lines, -0 lines) Patch
M runtime/bin/file.dart View 2 chunks +66 lines, -0 lines 0 comments Download
M runtime/bin/file_impl.dart View 1 5 chunks +141 lines, -0 lines 0 comments Download
M tests/standalone/src/FileTest.dart View 1 2 chunks +126 lines, -0 lines 0 comments Download
A tests/standalone/src/read_as_text.dat View 1 1 chunk +1 line, -0 lines 0 comments Download

Messages

Total messages: 5 (0 generated)
Mads Ager (google)
8 years, 10 months ago (2012-02-23 15:37:07 UTC) #1
Søren Gjesse
lgtm, with suggestions http://codereview.chromium.org/9452014/diff/1/runtime/bin/file_impl.dart File runtime/bin/file_impl.dart (right): http://codereview.chromium.org/9452014/diff/1/runtime/bin/file_impl.dart#newcode834 runtime/bin/file_impl.dart:834: var chunks = []; We have ...
8 years, 10 months ago (2012-02-24 07:24:51 UTC) #2
Mads Ager (google)
http://codereview.chromium.org/9452014/diff/1/runtime/bin/file_impl.dart File runtime/bin/file_impl.dart (right): http://codereview.chromium.org/9452014/diff/1/runtime/bin/file_impl.dart#newcode834 runtime/bin/file_impl.dart:834: var chunks = []; On 2012/02/24 07:24:51, Søren Gjesse ...
8 years, 10 months ago (2012-02-24 13:11:17 UTC) #3
Bob Nystrom
Drive-by comment: it seems to me like all of these would be more pleasant to ...
8 years, 10 months ago (2012-02-24 18:10:10 UTC) #4
Mads Ager (google)
8 years, 10 months ago (2012-02-27 08:34:35 UTC) #5
On 2012/02/24 18:10:10, Bob Nystrom wrote:
> Drive-by comment: it seems to me like all of these would be more pleasant to
use
> if they returned futures instead of requiring the user to assign to a setter:
> 
> var foo = new File('foo.txt');
> foo.readAsTextHandler = (text) {
>   print(text);
> }
> foo.readAsText();
> 
> versus:
> 
> new File('foo.txt').readAsText().then((text) {
>   print(text);
> }
> 
> The future code is shorter and naturally flows from left to right (you
indicate
> the operation first and then specify what you do with the result). In general,
I
> find the "handler" pattern that the IO libraries use confusing. What would
> happen if I did something like:
> 
> var foo = new File('foo.txt');
> foo.readAsTextHandler = (text) {
>   print(text);
> }
> foo.readAsBytes(); // <- not text
> 
> Is the motivation behind the handlers documented somewhere?

The motivation for the handlers is only documented in various mail threads. The
motivation is that we need repeated data events for the streaming APIs. In order
to keep the interfaces consistent we are sticking with the events and handlers
for now.

The handlers is a fairly low-level API on top of which it is easy to build other
abstractions later on. As an example, futures are easy to build on top of this.

Similarly, if we want a different style of event-handler registration, that
should be a fairly simple change as well. We could move to "file.on.readAsText =
...;" later on.

Powered by Google App Engine
This is Rietveld 408576698