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

Side by Side Diff: runtime/bin/vmservice_dartium.cc

Issue 1534523002: Compress Observatory assets (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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 | « runtime/bin/vmservice_dartium.h ('k') | runtime/tools/create_archive.py » ('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 #include "bin/vmservice_dartium.h" 5 #include "bin/vmservice_dartium.h"
6 6
7 #include "bin/builtin.h" 7 #include "bin/builtin.h"
8 #include "bin/dartutils.h" 8 #include "bin/dartutils.h"
9 #include "bin/eventhandler.h" 9 #include "bin/eventhandler.h"
10 #include "bin/platform.h" 10 #include "bin/platform.h"
11 #include "bin/thread.h" 11 #include "bin/thread.h"
12 #include "bin/vmservice_impl.h" 12 #include "bin/vmservice_impl.h"
13 #include "zlib/zlib.h"
13 14
14 namespace dart { 15 namespace dart {
15 namespace bin { 16 namespace bin {
16 17
17 #define CHECK_RESULT(result) \ 18 #define CHECK_RESULT(result) \
18 if (Dart_IsError(result)) { \ 19 if (Dart_IsError(result)) { \
19 fprintf(stderr, "CHECK_RESULT failed: %s", Dart_GetError(result)); \ 20 fprintf(stderr, "CHECK_RESULT failed: %s", Dart_GetError(result)); \
20 Dart_ExitScope(); \ 21 Dart_ExitScope(); \
21 Dart_ShutdownIsolate(); \ 22 Dart_ShutdownIsolate(); \
22 return 0; \ 23 return 0; \
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 const char* VmServiceServer::GetServerIP() { 86 const char* VmServiceServer::GetServerIP() {
86 return VmService::GetServerIP(); 87 return VmService::GetServerIP();
87 } 88 }
88 89
89 90
90 intptr_t VmServiceServer::GetServerPort() { 91 intptr_t VmServiceServer::GetServerPort() {
91 return VmService::GetServerPort(); 92 return VmService::GetServerPort();
92 } 93 }
93 94
94 95
96 void VmServiceServer::DecompressAssets(const uint8_t* input,
97 unsigned int input_len,
98 uint8_t** output,
99 unsigned int* output_length) {
100 ASSERT(input != NULL);
101 ASSERT(input_len > 0);
102 ASSERT(output != NULL);
103 ASSERT(output_length != NULL);
104
105 // Initialize output.
106 *output = NULL;
107 *output_length = 0;
108
109 const intptr_t kChunkSize = 256 * 1024;
110 uint8_t chunk_out[kChunkSize];
111 z_stream strm;
112 strm.zalloc = Z_NULL;
113 strm.zfree = Z_NULL;
114 strm.opaque = Z_NULL;
115 strm.avail_in = 0;
116 strm.next_in = 0;
117 int ret = inflateInit2(&strm, 32 + MAX_WBITS);
118 ASSERT(ret == Z_OK);
119
120 unsigned int input_cursor = 0;
121 unsigned int output_cursor = 0;
122 do {
123 // Setup input.
124 unsigned int size_in = input_len - input_cursor;
125 if (size_in > kChunkSize) {
126 size_in = kChunkSize;
127 }
128 strm.avail_in = size_in;
129 strm.next_in = const_cast<uint8_t*>(&input[input_cursor]);
130
131 // Inflate until we've exhausted the current input chunk.
132 do {
133 // Setup output.
134 strm.avail_out = kChunkSize;
135 strm.next_out = &chunk_out[0];
136 // Inflate.
137 ret = inflate(&strm, Z_SYNC_FLUSH);
138 // We either hit the end of the stream or made forward progress.
139 ASSERT((ret == Z_STREAM_END) || (ret == Z_OK));
140 // Grow output buffer size.
141 unsigned int size_out = kChunkSize - strm.avail_out;
142 *output_length += size_out;
143 *output = reinterpret_cast<uint8_t*>(realloc(*output, *output_length));
144 // Copy output.
145 memmove(&((*output)[output_cursor]), &chunk_out[0], size_out);
146 output_cursor += size_out;
147 } while (strm.avail_out == 0);
148
149 // We've processed size_in bytes.
150 input_cursor += size_in;
151
152 // We're finished decompressing when zlib tells us.
153 } while (ret != Z_STREAM_END);
154
155 inflateEnd(&strm);
156 }
157
95 /* DISALLOW_ALLOCATION */ 158 /* DISALLOW_ALLOCATION */
96 void VmServiceServer::operator delete(void* pointer) { 159 void VmServiceServer::operator delete(void* pointer) {
97 fprintf(stderr, "unreachable code\n"); 160 fprintf(stderr, "unreachable code\n");
98 abort(); 161 abort();
99 } 162 }
100 163
101 } // namespace bin 164 } // namespace bin
102 } // namespace dart 165 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/vmservice_dartium.h ('k') | runtime/tools/create_archive.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698