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

Side by Side Diff: sdk/lib/vmservice/asset.dart

Issue 2754013002: Format all dart: library files (Closed)
Patch Set: Format all dart: library files Created 3 years, 9 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 unified diff | Download patch
« no previous file with comments | « sdk/lib/typed_data/typed_data.dart ('k') | sdk/lib/vmservice/client.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart._vmservice; 5 part of dart._vmservice;
6 6
7 class Asset { 7 class Asset {
8 final String name; 8 final String name;
9 final Uint8List data; 9 final Uint8List data;
10 10
11 Asset(this.name, this.data); 11 Asset(this.name, this.data);
12 12
13 String get mimeType { 13 String get mimeType {
14 var extensionStart = name.lastIndexOf('.'); 14 var extensionStart = name.lastIndexOf('.');
15 var extension = name.substring(extensionStart+1); 15 var extension = name.substring(extensionStart + 1);
16 switch (extension) { 16 switch (extension) {
17 case 'html': 17 case 'html':
18 return 'text/html; charset=UTF-8'; 18 return 'text/html; charset=UTF-8';
19 case 'dart': 19 case 'dart':
20 return 'application/dart; charset=UTF-8'; 20 return 'application/dart; charset=UTF-8';
21 case 'js': 21 case 'js':
22 return 'application/javascript; charset=UTF-8'; 22 return 'application/javascript; charset=UTF-8';
23 case 'css': 23 case 'css':
24 return 'text/css; charset=UTF-8'; 24 return 'text/css; charset=UTF-8';
25 case 'gif': 25 case 'gif':
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 int get cursor => _cursor; 94 int get cursor => _cursor;
95 void set cursor(int cursor) { 95 void set cursor(int cursor) {
96 _cursor = cursor; 96 _cursor = cursor;
97 if (_cursor > length) { 97 if (_cursor > length) {
98 _cursor = length; 98 _cursor = length;
99 } 99 }
100 } 100 }
101 } 101 }
102 102
103 class _TarArchive { 103 class _TarArchive {
104 static const List<int> tarMagic = const [ 0x75, 0x73, 0x74, 0x61, 0x72, 0 ]; 104 static const List<int> tarMagic = const [0x75, 0x73, 0x74, 0x61, 0x72, 0];
105 static const List<int> tarVersion = const [ 0x30, 0x30 ]; 105 static const List<int> tarVersion = const [0x30, 0x30];
106 static const int tarHeaderSize = 512; 106 static const int tarHeaderSize = 512;
107 static const int tarHeaderFilenameSize = 100; 107 static const int tarHeaderFilenameSize = 100;
108 static const int tarHeaderFilenameOffset = 0; 108 static const int tarHeaderFilenameOffset = 0;
109 static const int tarHeaderSizeSize = 12; 109 static const int tarHeaderSizeSize = 12;
110 static const int tarHeaderSizeOffset = 124; 110 static const int tarHeaderSizeOffset = 124;
111 static const int tarHeaderTypeSize = 1; 111 static const int tarHeaderTypeSize = 1;
112 static const int tarHeaderTypeOffset = 156; 112 static const int tarHeaderTypeOffset = 156;
113 static const int tarHeaderFileType = 0x30; 113 static const int tarHeaderFileType = 0x30;
114 114
115 static String _readCString(_ByteStream bs, int length) { 115 static String _readCString(_ByteStream bs, int length) {
(...skipping 29 matching lines...) Expand all
145 return result; 145 return result;
146 } 146 }
147 147
148 static void _skipContents(_ByteStream bs, int size) { 148 static void _skipContents(_ByteStream bs, int size) {
149 bs.skip(size); 149 bs.skip(size);
150 bs.seekToNextBlock(tarHeaderSize); 150 bs.seekToNextBlock(tarHeaderSize);
151 } 151 }
152 152
153 static int _readSize(_ByteStream bs) { 153 static int _readSize(_ByteStream bs) {
154 String octalSize = _readCString(bs, tarHeaderSizeSize); 154 String octalSize = _readCString(bs, tarHeaderSizeSize);
155 return int.parse(octalSize, 155 return int.parse(octalSize, radix: 8, onError: (_) => 0);
156 radix: 8,
157 onError: (_) => 0);
158 } 156 }
159 157
160 static int _readType(_ByteStream bs) { 158 static int _readType(_ByteStream bs) {
161 return bs.readByte(); 159 return bs.readByte();
162 } 160 }
163 161
164 static bool _endOfArchive(_ByteStream bs) { 162 static bool _endOfArchive(_ByteStream bs) {
165 if (bs.remaining < (tarHeaderSize * 2)) { 163 if (bs.remaining < (tarHeaderSize * 2)) {
166 return true; 164 return true;
167 } 165 }
168 for (int i = 0; i < (tarHeaderSize * 2); i++) { 166 for (int i = 0; i < (tarHeaderSize * 2); i++) {
169 if (bs.peekByte(i) != 0) { 167 if (bs.peekByte(i) != 0) {
170 return false; 168 return false;
171 } 169 }
172 } 170 }
173 return true; 171 return true;
174 } 172 }
175 173
176 final _ByteStream _bs; 174 final _ByteStream _bs;
177 175
178 _TarArchive(Uint8List bytes) 176 _TarArchive(Uint8List bytes) : _bs = new _ByteStream(bytes);
179 : _bs = new _ByteStream(bytes);
180 177
181 bool hasNext() { 178 bool hasNext() {
182 return !_endOfArchive(_bs); 179 return !_endOfArchive(_bs);
183 } 180 }
184 181
185 Asset next() { 182 Asset next() {
186 int startOfBlock = _bs.cursor; 183 int startOfBlock = _bs.cursor;
187 String filename = _readFilename(_bs); 184 String filename = _readFilename(_bs);
188 _bs.cursor = startOfBlock + tarHeaderSizeOffset; 185 _bs.cursor = startOfBlock + tarHeaderSizeOffset;
189 int size = _readSize(_bs); 186 int size = _readSize(_bs);
190 _bs.cursor = startOfBlock + tarHeaderTypeOffset; 187 _bs.cursor = startOfBlock + tarHeaderTypeOffset;
191 int type = _readType(_bs); 188 int type = _readType(_bs);
192 _bs.seekToNextBlock(tarHeaderSize); 189 _bs.seekToNextBlock(tarHeaderSize);
193 if (type != tarHeaderFileType) { 190 if (type != tarHeaderFileType) {
194 _skipContents(_bs, size); 191 _skipContents(_bs, size);
195 return null; 192 return null;
196 } 193 }
197 Uint8List bytes = _readContents(_bs, size); 194 Uint8List bytes = _readContents(_bs, size);
198 return new Asset(filename, bytes); 195 return new Asset(filename, bytes);
199 } 196 }
200 } 197 }
OLDNEW
« no previous file with comments | « sdk/lib/typed_data/typed_data.dart ('k') | sdk/lib/vmservice/client.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698