| Index: src/bz2-decompress.cc
|
| diff --git a/src/bz2-decompress.cc b/src/bz2-decompress.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..62f746897fd04c3b4fc9b40022f98827e6b78349
|
| --- /dev/null
|
| +++ b/src/bz2-decompress.cc
|
| @@ -0,0 +1,77 @@
|
| +// Copyright 2011 the V8 project authors. All rights reserved.
|
| +// Redistribution and use in source and binary forms, with or without
|
| +// modification, are permitted provided that the following conditions are
|
| +// met:
|
| +//
|
| +// * Redistributions of source code must retain the above copyright
|
| +// notice, this list of conditions and the following disclaimer.
|
| +// * Redistributions in binary form must reproduce the above
|
| +// copyright notice, this list of conditions and the following
|
| +// disclaimer in the documentation and/or other materials provided
|
| +// with the distribution.
|
| +// * Neither the name of Google Inc. nor the names of its
|
| +// contributors may be used to endorse or promote products derived
|
| +// from this software without specific prior written permission.
|
| +//
|
| +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| +
|
| +#ifdef COMPRESS_STARTUP_DATA_BZ2
|
| +#include <bzlib.h>
|
| +#endif
|
| +
|
| +#include "bz2-decompress.h"
|
| +#include "v8.h"
|
| +
|
| +BZip2Decompressor::BZip2Decompressor()
|
| + : raw_data(new char*[v8::V8::GetCompressedStartupDataCount()]) {
|
| +}
|
| +
|
| +
|
| +BZip2Decompressor::~BZip2Decompressor() {
|
| + for (int i = 0; i < v8::V8::GetCompressedStartupDataCount(); ++i) {
|
| + delete[] raw_data[i];
|
| + }
|
| + delete[] raw_data;
|
| +}
|
| +
|
| +
|
| +int BZip2Decompressor::DecompressStartupData() {
|
| +#ifdef COMPRESS_STARTUP_DATA_BZ2
|
| + ASSERT_EQ(v8::StartupData::kBZip2,
|
| + v8::V8::GetCompressedStartupDataAlgorithm());
|
| + int compressed_data_count = v8::V8::GetCompressedStartupDataCount();
|
| + v8::StartupData* compressed_data = new v8::StartupData[compressed_data_count];
|
| + v8::V8::GetCompressedStartupData(compressed_data);
|
| + for (int i = 0; i < compressed_data_count; ++i) {
|
| + unsigned int decompressed_size = compressed_data[i].raw_size;
|
| + char* decompressed = raw_data[i] = new char[decompressed_size];
|
| + if (compressed_data[i].compressed_size != 0) {
|
| + int result =
|
| + BZ2_bzBuffToBuffDecompress(decompressed,
|
| + &decompressed_size,
|
| + const_cast<char*>(compressed_data[i].data),
|
| + compressed_data[i].compressed_size,
|
| + 0, 1);
|
| + if (result != BZ_OK) return result;
|
| + } else {
|
| + ASSERT_EQ(0, decompressed_size);
|
| + }
|
| + compressed_data[i].data = decompressed;
|
| + compressed_data[i].raw_size = decompressed_size;
|
| + }
|
| + v8::V8::SetDecompressedStartupData(compressed_data);
|
| + return BZ_OK;
|
| +#else
|
| + return 0;
|
| +#endif // COMPRESS_STARTUP_DATA_BZ2
|
| +}
|
|
|