示例#1
0
        /// <inheritdoc />
        protected override bool ReadChunk(Stream stream, out MemoryStream chunk)
        {
            chunk = null;
            var bytes = new byte[4];

            if (stream.Read(bytes, 0, 4) == 0)
            {
                return(false);
            }
            int length = BitConverter.ToInt32(bytes, 0);

            if (length <= 0 || length > BlockSize * 2)
            {
                UserErrorException.ThrowUserErrorException("Invalid input file format");
            }

            var buffer = new byte[length];

            if (stream.Read(buffer, 0, length) < length)
            {
                UserErrorException.ThrowUserErrorException("Invalid input file format. File is too short");
            }

            chunk = new MemoryStream(buffer);

            return(true);
        }
示例#2
0
        /// <summary>
        ///     Rethrows exception to be shown to user in some specific cases
        /// </summary>
        public static void ConvertFileExceptions(this Exception exception)
        {
            switch (exception)
            {
            case IOException _:
            case UnauthorizedAccessException _:
            case InvalidDataException _:     //this is gzip case
                //SecurityException _: //should not be thrown in normal run case:

                UserErrorException.ThrowUserErrorException($"Error processing file: {exception.Message}");

                break;
            }
        }
示例#3
0
        public static void Main(string[] args)
        {
            ExceptionManager.EnsureManagerInitialized();

            args = args.Where(str => !string.IsNullOrEmpty(str)).ToArray();

            if (args.Length != 3)
            {
                UserErrorException.ThrowUserErrorException("There should be 3 arguments");
            }

            bool compress = ParseMode(args[0]);


            string inputPath  = args[1];
            string outputPath = args[2];

            ZipZipProcessing.Process(inputPath, outputPath, compress);
        }