예제 #1
0
        private string CodeToBase64(string code)
        {
            for (; ; )
            {
                string ret = new Base64Unit().Encode(Encoding.UTF8.GetBytes(code));

                if (ret[ret.Length - 1] != '=')
                    return ret;

                code += ' ';
            }
        }
예제 #2
0
        private string ScriptToBase64(string script)
        {
            for (; ;)
            {
                string ret = new Base64Unit().Encode(Encoding.UTF8.GetBytes(script));

                if (ret[ret.Length - 1] != '=')
                {
                    return(ret);
                }

                script += ' ';
            }
        }
예제 #3
0
        private string EmbedSrcFile(string text, int p, int q)
        {
            if (30 < this.ESF_Depth)
            {
                throw new Exception("So deep");
            }

            this.ESF_Depth++;
            try
            {
                string srcFile = text.Substring(p, q - p);
                srcFile = srcFile.Replace("/", "\\");

                if (srcFile == "" || File.Exists(srcFile) == false)
                {
                    throw new Exception("Bad srcFile");
                }

                string srcExt    = Path.GetExtension(srcFile);
                string lwrSrcExt = srcExt.ToLower();
                byte[] srcData;
                string srcType;

                if (lwrSrcExt == ".html")
                {
                    string srcText = this.GetOneHtml(srcFile);
                    srcData = StringTools.ENCODING_SJIS.GetBytes(srcText);
                    srcType = "text/html";
                }
                else
                {
                    srcData = File.ReadAllBytes(srcFile);
                    srcType = this.GetTypeByExt(srcExt);
                }
                string eText = new Base64Unit().Encode(srcData);

                return(text.Substring(0, p) + "data:" + srcType + ";base64," + eText + text.Substring(q));
            }
            finally
            {
                this.ESF_Depth--;
            }
        }
예제 #4
0
파일: Service.cs 프로젝트: stackprobe/Post2
        private object Upload()
        {
            this.LoggedIn();

            TrySlimdown(100);

            Group  group     = this.LiteGroup.GetGroup();
            string dir       = Path.Combine(group.Dir, Consts.FILE_BUNDLE_LOCAL_DIR);
            string localFile = DenebolaToolkit.GetFairLocalPath(this.TPrm["LocalFile"].StringValue, dir);
            string file      = Path.Combine(dir, localFile);

            if (File.Exists(file) == false)
            {
                throw new Exception("指定されたファイルは存在しません。");
            }

            long offset = long.Parse(this.TPrm["Offset"].StringValue);

            if (offset < 0L || LongTools.IMAX_64 < offset)
            {
                throw new Exception("不正なオフセット値です。" + offset);
            }

            byte[] data     = new Base64Unit().Decode(this.TPrm["Data"].StringValue);
            long   fileSize = new FileInfo(file).Length;

            if (fileSize < offset)
            {
                throw new Exception("ファイルサイズより大きなオフセット値です。" + offset);
            }

            // offset < fileSize の場合は、既に正常に書き込まれたと見なす。

            if (offset == fileSize)
            {
                using (FileStream writer = new FileStream(file, FileMode.Append, FileAccess.Write))
                {
                    writer.Write(data, 0, data.Length);
                }
            }
            return("OK");
        }