예제 #1
0
        public void ExtractFile(CompressedFileRecord objRecord, Stream objOutputStream)
        {
            if (objRecord == null)
            {
                throw new ArgumentNullException("objRecord", "A valid non-null CompressedFileRecord is required.");
            }
            if (objOutputStream == null)
            {
                throw new ArgumentNullException("objOutputStream", "A valid non-null Stream is required.");
            }

            if (CompressedFileRecordManager.Exists(objRecord) == false)
            {
                throw new Exception("A record for '" + objRecord.RelativePath + "' could not be found.");
            }

            CompressedFileRecordState enuRecordState = CompressedFileRecordManager.GetRecordState(objRecord);

            if (enuRecordState == CompressedFileRecordState.Deleted)
            {
                throw new Exception("A record for '" + objRecord.RelativePath + "' could not be found.");
            }

            ExtractFile(objRecord, enuRecordState, objOutputStream);
        }
예제 #2
0
        public byte[] ExtractFile(CompressedFileRecord objRecord)
        {
            if (objRecord == null)
            {
                throw new ArgumentNullException("objRecord", "A valid non-null CompressedFileRecord is required.");
            }

            if (CompressedFileRecordManager.Exists(objRecord) == false)
            {
                throw new Exception("A record for '" + objRecord.RelativePath + "' could not be found.");
            }

            CompressedFileRecordState enuRecordState = CompressedFileRecordManager.GetRecordState(objRecord);

            if (enuRecordState == CompressedFileRecordState.Deleted)
            {
                throw new Exception("A record for '" + objRecord.RelativePath + "' could not be found.");
            }

            using (MemoryStream objMemoryStream = new MemoryStream())
            {
                ExtractFile(objRecord, enuRecordState, objMemoryStream);
                objMemoryStream.Position = 0;

                return(objMemoryStream.ToArray());
            }
        }
예제 #3
0
        public FileInfo ExtractFile(CompressedFileRecord objRecord, string strPath)
        {
            if (objRecord == null)
            {
                throw new ArgumentNullException("objRecord", "A valid non-null CompressedFileRecord is required.");
            }
            if (strPath == null)
            {
                throw new ArgumentNullException("strPath", "A valid non-null string is required.");
            }

            if (CompressedFileRecordManager.Exists(objRecord) == false)
            {
                throw new Exception("A record for '" + objRecord.RelativePath + "' could not be found.");
            }

            CompressedFileRecordState enuRecordState = CompressedFileRecordManager.GetRecordState(objRecord);

            if (enuRecordState == CompressedFileRecordState.Deleted)
            {
                throw new Exception("A record for '" + objRecord.RelativePath + "' could not be found.");
            }

            string strFilePath      = Path.Combine(strPath, objRecord.RelativeFilePath);
            string strDirectoryPath = Path.GetDirectoryName(strFilePath);

            if (Directory.Exists(strDirectoryPath) == false)
            {
                Directory.CreateDirectory(strDirectoryPath);
            }

            using (FileStream objFileStream = new FileStream(strFilePath, FileMode.Create, FileAccess.Write))
            {
                ExtractFile(objRecord, enuRecordState, objFileStream);
            }

            FileInfo objFileInfo = new FileInfo(strFilePath);

            return(objFileInfo);
        }