int main(int argc, char **argv) { //::testing::InitGoogleTest(&argc, argv); //return RUN_ALL_TESTS(); if(argc != 3){ cout << "Uso: " << endl; cout << argv[0] << " -c archivoAComprimir"<< endl; cout << argv[0] << " -d archivoADescomprimir"<< endl; exit(1); } string path=argv[2]; if(!strcmp(argv[1],"-c")){ Compressor * comp = new Compressor(); comp->compress(path); //remove(path.c_str()); delete comp; } if(!strcmp(argv[1],"-d")){ Decompressor * decomp = new Decompressor(); decomp->decompress(path); delete decomp; } return 0; }
// Returns a gzip decompressed version of the provided string. inline Try<std::string> decompress(const std::string& compressed) { Decompressor decompressor; Try<std::string> decompressed = decompressor.decompress(compressed); // Ensure that the decompression stream does not expect more input. if (decompressed.isSome() && !decompressor.finished()) { return Error("More input is expected"); } return decompressed; }
void unpackMatrixPlusV3(ByteUnpacker &src, u16 *dst, size_t L) { // extract key numbers: const vector<size_t> header = src.pop<size_t>(5); const size_t nGood = header[0]; const size_t nBad = header[1]; const size_t RANK_GOOD = header[2]; //const size_t rankBad = header[3]; const bool uses16Bit = header[4]; const int N = nGood + nBad; //assert(rankBad == L); const fmat basisGood( POP_CONSTRUCTOR(float, L, RANK_GOOD) ); // extract partion: const Col<u8> partion( src.popPtr<u8>(N), N, false, true ); const uvec goodIdx = find(partion == 0); const uvec badIdx = find(partion == 1); assert( goodIdx.n_elem == nGood && badIdx.n_elem == nBad); // make a matrix using the memory pointed to by dst: Mat<u16> restored(dst, L, N, false, true); //decompress the good traces: if ( nGood > 0) { if ( uses16Bit ) { // extract scores: const Mat<i16> scoreGood( POP_CONSTRUCTOR(i16, nGood, RANK_GOOD) ); //restored.cols(goodIdx) = convToValidU16( basisGood * convToFloat(scoreGood).t() ); restored.cols(goodIdx) = convToValidU16( basisGood * scoreGood.t() ); } else { // extract scores: const Mat<i32> scoreGood( POP_CONSTRUCTOR(i32, nGood, RANK_GOOD) ); // fill this matrix with the matrix multiplications: //restored.cols(goodIdx) = convToValidU16( basisGood * conv_to<fmat>::from(scoreGood).t() ); restored.cols(goodIdx) = convToValidU16( basisGood * scoreGood.t() ); } } //Decompress the bad data, output the uncompressed to restored.cols(badIdx); if ( nBad > 0) { vector<size_t> sSize = src.pop<size_t>(1); const vector<uint8_t> deltaIn = src.pop<uint8_t>(sSize[0]); Decompressor dc; size_t nCols; size_t nRows; size_t oL; vector<uint16_t> deltaOut; dc.decompress(deltaIn,nRows,nCols, oL, deltaOut); Mat<uint16_t> dataBadMat(&deltaOut[0], L, nBad, false, true); restored.cols(badIdx) = dataBadMat; } }
int main() { Compressor c; //cout << "compressing" << endl; // c.compress("/auto_home/nlephilippe/Téléchargements/test1.txt", "/auto_home/nlephilippe/Téléchargements/compc"); c.compress("/home/noe/Téléchargements/test1.txt", "/home/noe/Téléchargements/compc"); // cout << endl; Decompressor d; //cout << "decompressing" << endl; //d.decompress("/auto_home/nlephilippe/Téléchargements/compc", "/auto_home/nlephilippe/Téléchargements/outc.bin"); d.decompress("/home/noe/Téléchargements/compc", "/home/noe/Téléchargements/outc.txt"); cout << endl; return 0; }
// Uncompress section contents if required. Note that this function // is called from parallelForEach, so it must be thread-safe. void InputSectionBase::maybeUncompress() { if (UncompressBuf || !Decompressor::isCompressedELFSection(Flags, Name)) return; Decompressor Dec = check(Decompressor::create(Name, toStringRef(Data), Config->IsLE, Config->Is64)); size_t Size = Dec.getDecompressedSize(); UncompressBuf.reset(new char[Size]()); if (Error E = Dec.decompress({UncompressBuf.get(), Size})) fatal(toString(this) + ": decompress failed: " + llvm::toString(std::move(E))); Data = makeArrayRef((uint8_t *)UncompressBuf.get(), Size); Flags &= ~(uint64_t)SHF_COMPRESSED; }
void processMsg( const char * msg, const size_t len ) { #ifdef HAVE_LIBZ if ( M_comp_level >= 0 ) { M_decomp.decompress( msg, len, Z_SYNC_FLUSH ); char * out; int size; M_decomp.getOutput( out, size ); if ( size > 0 ) { parseMsg( out, size ); } } else #endif { parseMsg( msg, len ); } }
Graphics::Surface *Animation::getFrame(int frameIndex) { if (frameIndex < _frameCount) { if (_frameList[frameIndex]._isCompressed) { Decompressor dec; byte *ddata = (byte *)malloc(_frameList[frameIndex]._dataSize); dec.decompress(_frameList[frameIndex]._compressedData, ddata, _frameList[frameIndex]._dataSize); int frameHeight = _frameList[frameIndex]._surface->h; int frameWidth = _frameList[frameIndex]._surface->w; for (uint16 i = 0; i < frameHeight; i++) { memcpy(_frameList[frameIndex]._surface->getBasePtr(0, i), ddata + frameWidth * i, frameWidth); } free(ddata); free(_frameList[frameIndex]._compressedData); _frameList[frameIndex]._compressedData = nullptr; _frameList[frameIndex]._dataSize = 0; _frameList[frameIndex]._isCompressed = false; } return _frameList[frameIndex]._surface; } else { error("getFrame() frameIndex: %d, frameCount: %d", frameIndex, _frameCount); } }
void SubscriberInstance::ReceivedMetadata(const vector<uint8_t>& payload) { if (!m_autoParseMetadata) return; if (payload.empty()) { ErrorMessage("Received empty payload for meta data refresh."); return; } vector<uint8_t>* uncompressed; // Step 1: Decompress meta-data if needed if (IsMetadataCompressed()) { // Perform zlib decompression on buffer const MemoryStream payloadStream(payload); Decompressor decompressor; decompressor.push(GZipDecompressor()); decompressor.push(payloadStream); uncompressed = new vector<uint8_t>(); CopyStream(decompressor, *uncompressed); } else { uncompressed = const_cast<vector<uint8_t>*>(&payload); } // Step 2: Load string into an XML parser xml_document document; const xml_parse_result result = document.load_buffer_inplace(static_cast<void*>(uncompressed->data()), uncompressed->size()); if (result.status != xml_parse_status::status_ok) { if (IsMetadataCompressed()) delete uncompressed; stringstream errorMessageStream; errorMessageStream << "Failed to parse meta data XML, status code = 0x" << hex << result.status; ErrorMessage(errorMessageStream.str()); return; } // Find root node xml_node rootNode = document.document_element(); // Query DeviceDetail records from metadata map<string, DeviceMetadataPtr> devices; for (xml_node device = rootNode.child("DeviceDetail"); device; device = device.next_sibling("DeviceDetail")) { DeviceMetadataPtr deviceMetadata = NewSharedPtr<DeviceMetadata>(); deviceMetadata->Acronym = device.child_value("Acronym"); deviceMetadata->Name = device.child_value("Name"); deviceMetadata->UniqueID = ToGuid(device.child_value("UniqueID")); deviceMetadata->AccessID = stoi(Coalesce(device.child_value("AccessID"), "0")); deviceMetadata->ParentAcronym = device.child_value("ParentAcronym"); deviceMetadata->ProtocolName = device.child_value("ProtocolName"); deviceMetadata->FramesPerSecond = stoi(Coalesce(device.child_value("FramesPerSecond"), "30")); deviceMetadata->CompanyAcronym = device.child_value("CompanyAcronym"); deviceMetadata->VendorAcronym = device.child_value("vendorAcronym"); deviceMetadata->VendorDeviceName = device.child_value("VendorDeviceName"); deviceMetadata->Longitude = stod(Coalesce(device.child_value("Longitude"), "0.0")); deviceMetadata->Latitude = stod(Coalesce(device.child_value("Latitude"), "0.0")); deviceMetadata->UpdatedOn = ParseXMLTimestamp(device.child_value("UpdatedOn")); devices.insert(pair<string, DeviceMetadataPtr>(deviceMetadata->Acronym, deviceMetadata)); } // Query MeasurementDetail records from metadata map<Guid, MeasurementMetadataPtr> measurements; for (xml_node device = rootNode.child("MeasurementDetail"); device; device = device.next_sibling("MeasurementDetail")) { MeasurementMetadataPtr measurementMetadata = NewSharedPtr<MeasurementMetadata>(); measurementMetadata->DeviceAcronym = device.child_value("DeviceAcronym"); measurementMetadata->ID = device.child_value("ID"); measurementMetadata->SignalID = ToGuid(device.child_value("SignalID")); measurementMetadata->PointTag = device.child_value("PointTag"); measurementMetadata->Reference = SignalReference(string(device.child_value("SignalReference"))); measurementMetadata->PhasorSourceIndex = stoi(Coalesce(device.child_value("PhasorSourceIndex"), "0")); measurementMetadata->Description = device.child_value("Description"); measurementMetadata->UpdatedOn = ParseXMLTimestamp(device.child_value("UpdatedOn")); measurements.insert(pair<Guid, MeasurementMetadataPtr>(measurementMetadata->SignalID, measurementMetadata)); // Lookup associated device auto iterator = devices.find(measurementMetadata->DeviceAcronym); if (iterator != devices.end()) { // Add measurement to device's measurement list DeviceMetadataPtr& deviceMetaData = iterator->second; deviceMetaData->Measurements.push_back(measurementMetadata); } } // Query PhasorDetail records from metadata uint16_t phasorCount = 0; for (xml_node device = rootNode.child("PhasorDetail"); device; device = device.next_sibling("PhasorDetail")) { PhasorMetadataPtr phasorMetadata = NewSharedPtr<PhasorMetadata>(); phasorMetadata->DeviceAcronym = device.child_value("DeviceAcronym"); phasorMetadata->Label = device.child_value("Label"); phasorMetadata->Type = device.child_value("Type"); phasorMetadata->Phase = device.child_value("Phase"); phasorMetadata->SourceIndex = stoi(Coalesce(device.child_value("SourceIndex"), "0")); phasorMetadata->UpdatedOn = ParseXMLTimestamp(device.child_value("UpdatedOn")); // Create a new phasor reference PhasorReferencePtr phasorReference = NewSharedPtr<PhasorReference>(); phasorReference->Phasor = phasorMetadata; // Lookup associated device auto iterator = devices.find(phasorMetadata->DeviceAcronym); if (iterator == devices.end()) { // If associated device was not found, continue on stringstream errorMessageStream; errorMessageStream << "Could not find device " << phasorMetadata->DeviceAcronym << " referenced by phasor " << phasorMetadata->Label; ErrorMessage(errorMessageStream.str()); continue; } DeviceMetadataPtr& deviceMetadata = iterator->second; // Lookup associated phasor measurements uint16_t matchCount = 0; for (auto const& measurementMetadata : deviceMetadata->Measurements) { // Check if source indexes also match - if so, we found an associated measurement if (measurementMetadata->PhasorSourceIndex == phasorMetadata->SourceIndex) { // There should be two measurements that match DeviceAcronym and SourceIndex, // specifically one for the angle and one for the magnitude for each phasor if (measurementMetadata->Reference.Kind == SignalKind::Angle) { phasorReference->Angle = measurementMetadata; matchCount++; } else if (measurementMetadata->Reference.Kind == SignalKind::Magnitude) { phasorReference->Magnitude = measurementMetadata; matchCount++; } else { // Unexpected condition: stringstream errorMessageStream; errorMessageStream << "Encountered a " << SignalKindDescription[measurementMetadata->Reference.Kind] << " measurement \"" << measurementMetadata->Reference << "\" that had a matching SourceIndex for phasor: " << phasorMetadata->Label; ErrorMessage(errorMessageStream.str()); } // Stop looking if we have found both matches if (matchCount >= 2) break; } } // Add phasor to associated device meta data record deviceMetadata->Phasors.push_back(phasorReference); phasorCount++; } // Construct a "configuration frame" for each of the devices map<string, ConfigurationFramePtr> configurationFrames; ConstructConfigurationFrames(devices, measurements, configurationFrames); m_configurationUpdateLock.lock(); m_configurationFrames = configurationFrames; // Replace the configuration frames list m_devices = devices; // Replace the device metadata list m_measurements = measurements; // Replace the measurement metadata list m_configurationUpdateLock.unlock(); stringstream message; message << "Loaded " << devices.size() << " devices, " << measurements.size() << " measurements and " << phasorCount << " phasors from GEP meta data..."; StatusMessage(message.str()); // Release uncompressed buffer if (IsMetadataCompressed()) delete uncompressed; // Notify derived class that meta-data has been parsed and is now available ParsedMetadata(); }
//-------------------------------------------------------------- bool Decompress(const u8* buffer, int size, io::File* ostream) { Decompressor decompr; return decompr.decompress(buffer, size, ostream) && decompr.finish(ostream); }