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

Unified Diff: runtime/bin/file_impl.dart

Issue 10065013: Support length operation without opening file. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 | « runtime/bin/file.dart ('k') | runtime/bin/file_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file_impl.dart
diff --git a/runtime/bin/file_impl.dart b/runtime/bin/file_impl.dart
index d050772aa7b599097250a4ae60eedef88061fcc5..7432bc15584033699eb31c027c518ae42a07e2f8 100644
--- a/runtime/bin/file_impl.dart
+++ b/runtime/bin/file_impl.dart
@@ -217,12 +217,13 @@ class _FileUtils {
static final kSetPositionRequest = 8;
static final kTruncateRequest = 9;
static final kLengthRequest = 10;
- static final kFlushRequest = 11;
- static final kReadByteRequest = 12;
- static final kWriteByteRequest = 13;
- static final kReadListRequest = 14;
- static final kWriteListRequest = 15;
- static final kWriteStringRequest = 16;
+ static final kLengthFromNameRequest = 11;
+ static final kFlushRequest = 12;
+ static final kReadByteRequest = 13;
+ static final kWriteByteRequest = 14;
+ static final kReadListRequest = 15;
+ static final kWriteListRequest = 16;
+ static final kWriteStringRequest = 17;
static final kSuccessResponse = 0;
static final kIllegalArgumentResponse = 1;
@@ -265,6 +266,7 @@ class _FileUtils {
static delete(String name) native "File_Delete";
static fullPath(String name) native "File_FullPath";
static directory(String name) native "File_Directory";
+ static lengthFromName(String name) native "File_LengthFromName";
static int close(int id) native "File_Close";
static readByte(int id) native "File_ReadByte";
static readList(int id, List<int> buffer, int offset, int bytes)
@@ -354,6 +356,17 @@ class _FileUtils {
return result;
}
+ static int checkedLengthFromName(String name) {
+ if (name is !String) {
+ throw new IllegalArgumentException();
+ }
+ var result = lengthFromName(name);
+ if (result is OSError) {
+ throw new FileIOException("Cannot retrieve length for file", result);
+ }
+ return result;
+ }
+
static int checkReadWriteListArguments(int length, int offset, int bytes) {
if (offset < 0) return offset;
if (bytes < 0) return bytes;
@@ -507,6 +520,28 @@ class _File extends _FileBase implements File {
});
}
+ void length(void callback(int length)) {
+ _ensureFileService();
+ List request = new List(2);
+ request[0] = _FileUtils.kLengthFromNameRequest;
+ request[1] = _name;
+ _fileService.call(request).then((response) {
+ if (_isErrorResponse(response)) {
+ _reportError(response, "Cannot retrieve length for file");
+ } else {
+ callback(response);
+ }
+ });
+ }
+
+ int lengthSync() {
+ var result = _FileUtils.checkedLengthFromName(_name);
+ if (result is OSError) {
+ throw new FileIOException("Cannot retrieve lenght for file", result);
Søren Gjesse 2012/04/12 11:41:44 lenght -> length for -> of
Mads Ager (google) 2012/04/13 12:24:11 Done.
+ }
+ return result;
+ }
+
RandomAccessFile openSync([FileMode mode = FileMode.READ]) {
if (mode != FileMode.READ &&
mode != FileMode.WRITE &&
« no previous file with comments | « runtime/bin/file.dart ('k') | runtime/bin/file_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698