/*---------------------------------------------------------------------- | CreateEntry +---------------------------------------------------------------------*/ static NPT_Result CreateEntry(const char* root_path, const char* name, bool directory) { NPT_Result res; NPT_String path = root_path; NPT_DirectoryAppendToPath(path, name); if (directory) { res = NPT_DirectoryCreate(path, true); } else { NPT_File* file = new NPT_File(path); res = file->Open(NPT_FILE_OPEN_MODE_TRUNCATE | NPT_FILE_OPEN_MODE_WRITE | NPT_FILE_OPEN_MODE_CREATE); delete file; } return res; }
/*---------------------------------------------------------------------- | NPT_Zip::Deflate +---------------------------------------------------------------------*/ NPT_Result NPT_Zip::Deflate(NPT_File& in, NPT_File& out, int compression_level, Format format /* = ZLIB */) { // check parameters if (compression_level < NPT_ZIP_COMPRESSION_LEVEL_DEFAULT || compression_level > NPT_ZIP_COMPRESSION_LEVEL_MAX) { return NPT_ERROR_INVALID_PARAMETERS; } NPT_InputStreamReference input; NPT_CHECK(in.GetInputStream(input)); NPT_OutputStreamReference output; NPT_CHECK(out.GetOutputStream(output)); NPT_ZipDeflatingInputStream deflating_stream(input, compression_level, format); return NPT_StreamToStreamCopy(deflating_stream, *output.AsPointer()); }
/*---------------------------------------------------------------------- | TestFile +---------------------------------------------------------------------*/ static void TestFile(const char* filename) { NPT_File* input; NPT_InputStreamReference stream; NPT_Result result; // open the input file input = new NPT_File(filename); result = input->Open(NPT_FILE_OPEN_MODE_READ); if (NPT_FAILED(result)) { NPT_Debug("XmtTest1:: cannot open input (%d)\n", result); return; } result = input->GetInputStream(stream); // parse the buffer NPT_XmlParser parser; NPT_XmlNode* tree; result = parser.Parse(*stream, tree); if (NPT_FAILED(result)) { NPT_Debug("XmlTest1:: cannot parse input (%d)\n", result); return; } // dump the tree NPT_XmlWriter writer(2); NPT_File output(NPT_FILE_STANDARD_OUTPUT); output.Open(NPT_FILE_OPEN_MODE_WRITE); NPT_OutputStreamReference output_stream_ref; output.GetOutputStream(output_stream_ref); writer.Serialize(*tree, *output_stream_ref); // delete the tree delete tree; // delete the input delete input; }