OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 part of vmservice_io; | |
6 | |
7 String detectMimeType(String name) { | |
8 var extensionStart = name.lastIndexOf('.'); | |
9 var extension = name.substring(extensionStart+1); | |
10 switch (extension) { | |
11 case 'html': | |
12 return 'text/html; charset=UTF-8'; | |
13 case 'dart': | |
14 return 'application/dart; charset=UTF-8'; | |
15 case 'js': | |
16 return 'application/javascript; charset=UTF-8'; | |
17 case 'css': | |
18 return 'text/css; charset=UTF-8'; | |
19 case 'gif': | |
20 return 'image/gif'; | |
21 case 'png': | |
22 return 'image/png'; | |
23 case 'jpg': | |
24 return 'image/jpeg'; | |
25 case 'jpeg': | |
26 return 'image/jpeg'; | |
27 case 'svg': | |
28 return 'image/svg+xml'; | |
29 default: | |
30 return 'text/plain'; | |
31 } | |
32 } | |
33 | |
34 | |
35 class Resource { | |
36 final String name; | |
37 final String mimeType; | |
38 final List<int> data; | |
39 Resource(this.name, this.mimeType, this.data); | |
40 static final Map<String, Resource> resources = new Map<String, Resource>(); | |
41 } | |
42 | |
43 ZLibCodec _zlib; | |
44 | |
45 void _addResource(String name, List<int> data, bool compressed) { | |
46 var mimeType = detectMimeType(name); | |
47 if (compressed) { | |
48 if (_zlib == null) { | |
49 _zlib = new ZLibCodec(); | |
50 } | |
51 try { | |
52 data = _zlib.decode(data); | |
53 } catch(e) { | |
54 print('error decompressing service isolate resource: $name'); | |
55 return; | |
56 } | |
57 } | |
58 Resource resource = new Resource(name, mimeType, data); | |
59 Resource.resources[name] = resource; | |
60 } | |
61 | |
62 void _triggerResourceLoad() native "VMServiceIO_TriggerResourceLoad"; | |
OLD | NEW |