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

Unified Diff: pkg/barback/lib/src/file_pool.dart

Issue 261823008: Reorganize barback's source files. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: re-add barback/lib/src/internal_asset.dart Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/barback/lib/src/errors.dart ('k') | pkg/barback/lib/src/graph/asset_cascade.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/barback/lib/src/file_pool.dart
diff --git a/pkg/barback/lib/src/file_pool.dart b/pkg/barback/lib/src/file_pool.dart
deleted file mode 100644
index dab94091ab6f071fac3d21f3c685680b0fc3dcb9..0000000000000000000000000000000000000000
--- a/pkg/barback/lib/src/file_pool.dart
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-library barback.file_pool;
-
-import 'dart:async';
-import 'dart:convert';
-import 'dart:io';
-
-import 'package:stack_trace/stack_trace.dart';
-
-import 'pool.dart';
-import 'utils.dart';
-
-/// Manages a pool of files that are opened for reading to cope with maximum
-/// file descriptor limits.
-///
-/// If a file cannot be opened because too many files are already open, this
-/// will defer the open until a previously opened file is closed and then try
-/// again. If this doesn't succeed after a certain amount of time, the open
-/// will fail and the original "too many files" exception will be thrown.
-class FilePool {
- /// The underlying pool.
- ///
- /// The maximum number of allocated descriptors is based on empirical tests
- /// that indicate that beyond 32, additional file reads don't provide
- /// substantial additional throughput.
- final Pool _pool = new Pool(32, timeout: new Duration(seconds: 60));
-
- /// Opens the file at [path] for reading.
- ///
- /// When the returned stream is listened to, if there are too many files
- /// open, this will wait for a previously opened file to be closed and then
- /// try again.
- Stream<List<int>> openRead(String path) {
- return futureStream(_pool.request().then((resource) {
- return Chain.track(new File(path).openRead()).transform(
- new StreamTransformer.fromHandlers(handleDone: (sink) {
- sink.close();
- resource.release();
- }));
- }));
- }
-
- /// Reads [path] as a string using [encoding].
- ///
- /// If there are too many files open and the read fails, this will wait for
- /// a previously opened file to be closed and then try again.
- Future<String> readAsString(String path, Encoding encoding) {
- return _readAsBytes(path).then(encoding.decode);
- }
-
- /// Reads [path] as a list of bytes, using [openRead] to retry if there are
- /// failures.
- Future<List<int>> _readAsBytes(String path) {
- var completer = new Completer<List<int>>();
- var builder = new BytesBuilder();
-
- openRead(path).listen(builder.add, onDone: () {
- completer.complete(builder.takeBytes());
- }, onError: completer.completeError, cancelOnError: true);
-
- return completer.future;
- }
-}
« no previous file with comments | « pkg/barback/lib/src/errors.dart ('k') | pkg/barback/lib/src/graph/asset_cascade.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698