Esempio n. 1
0
        private void SetCompressEncoding(WebPageContext context)
        {
            if (!context.IsGET)
            {
                return;
            }
            ICompressor cpor = CompressorFactory.Create(context);

            if (cpor.IsAccepted(context))
            {
                cpor.SetEncoding(context);                           //支持压缩
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 压缩代码
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        protected virtual Stream CompressCode(string code)
        {
            if (code == null)
            {
                return(null);
            }
            //压缩
            byte[]       codeBytes = Encoding.UTF8.GetBytes(code);
            MemoryStream source    = new MemoryStream(codeBytes);

            var context = this.PageContext;

            ICompressor cpor = CompressorFactory.Create(context);

            if (cpor.IsAccepted(context))
            {
                //支持压缩
                MemoryStream target = new MemoryStream(codeBytes.Length);
                cpor.Compress(context, source, target);
                target.Position = 0;
                source          = target;
            }
            return(source);
        }