<commit_before>﻿using System.Collections.Generic;
using System.Text;
using System.IO;
using Qiniu.Http;
using Qiniu.Common;
using Qiniu.Util;

namespace Qiniu.Storage
{
    public class FormUploader
    {
        public static void uploadData(HttpManager httpManager, byte[] data, string key,
            string token, UploadOptions uploadOptions, CompletionCallback completionCallback)
        {
            PostArgs postArgs = new PostArgs();
            postArgs.Data = data;
            postArgs.Params = new Dictionary<string, string>();
            if (key != null)
            {
                postArgs.FileName = key;
            }
            //set file crc32 check
            if (uploadOptions != null && uploadOptions.CheckCrc32)
            {
                postArgs.Params.Add("crc32", string.Format("{0}", CRC32.CheckSumBytes(data, data.Length)));
            }
            httpManager.FileContentType = PostFileType.BYTES;
            upload(httpManager, postArgs, key, token, uploadOptions, completionCallback);
        }

        public static void uploadStream(HttpManager httpManager, Stream stream, string key, string token,
            UploadOptions uploadOptions, CompletionCallback completionCallback)
        {
            PostArgs postArgs = new PostArgs();
            postArgs.Stream = stream;
            postArgs.Params = new Dictionary<string, string>();
            if (key != null)
            {
                postArgs.FileName = key;
            }
            //set file crc32 check
            if (uploadOptions != null && uploadOptions.CheckCrc32)
            {
                long streamLength = stream.Length;
                byte[] buffer = new byte[streamLength];
                int cnt = stream.Read(buffer, 0, (int)streamLength);
                postArgs.Params.Add("crc32", string.Format("{0}", CRC32.CheckSumBytes(buffer, cnt)));
                postArgs.Stream.Seek(0, SeekOrigin.Begin);
            }
            httpManager.FileContentType = PostFileType.STREAM;
            upload(httpManager, postArgs, key, token, uploadOptions, completionCallback);
        }
 
        private static void upload(HttpManager httpManager, PostArgs postArgs, string key, string token,
            UploadOptions uploadOptions, CompletionCallback completionCallback)
        {
            //set key
            if (!string.IsNullOrEmpty(key))
            {
                postArgs.Params.Add("key", key);
            }
            //set token
            postArgs.Params.Add("token", token);
            //set mimeType
            string mimeType = "application/octet-stream";
            if (uploadOptions != null && !string.IsNullOrEmpty(uploadOptions.MimeType))
            {
                mimeType = uploadOptions.MimeType;
            }
            postArgs.MimeType = mimeType;
            //set extra params
            if (uploadOptions != null && uploadOptions.ExtraParams != null)
            {
                foreach (KeyValuePair<string, string> kvp in uploadOptions.ExtraParams)
                {
                    postArgs.Params.Add(kvp.Key, kvp.Value);
                }
            }
            //set progress callback and cancellation callback
            if (uploadOptions != null)
            {
                httpManager.ProgressCallback = uploadOptions.ProgressCallback;
                httpManager.CancellationCallback = uploadOptions.CancellationCallback;<commit_msg>Change form uploader method to member functions to be consistent with other sdks.<commit_after>﻿using System.Collections.Generic;
using System.Text;
using System.IO;
using Qiniu.Http;
using Qiniu.Common;
using Qiniu.Util;

namespace Qiniu.Storage
{
    public class FormUploader
    {
        public void uploadData(HttpManager httpManager, byte[] data, string key,
            string token, UploadOptions uploadOptions, CompletionCallback completionCallback)
        {
            PostArgs postArgs = new PostArgs();
            postArgs.Data = data;
            postArgs.Params = new Dictionary<string, string>();
            if (key != null)
            {
                postArgs.FileName = key;
            }
            //set file crc32 check
            if (uploadOptions != null && uploadOptions.CheckCrc32)
            {
                postArgs.Params.Add("crc32", string.Format("{0}", CRC32.CheckSumBytes(data, data.Length)));
            }
            httpManager.FileContentType = PostFileType.BYTES;
            upload(httpManager, postArgs, key, token, uploadOptions, completionCallback);
        }

        public void uploadStream(HttpManager httpManager, Stream stream, string key, string token,
            UploadOptions uploadOptions, CompletionCallback completionCallback)
        {
            PostArgs postArgs = new PostArgs();
            postArgs.Stream = stream;
            postArgs.Params = new Dictionary<string, string>();
            if (key != null)
            {
                postArgs.FileName = key;
            }
            //set file crc32 check
            if (uploadOptions != null && uploadOptions.CheckCrc32)
            {
                long streamLength = stream.Length;
                byte[] buffer = new byte[streamLength];
                int cnt = stream.Read(buffer, 0, (int)streamLength);
                postArgs.Params.Add("crc32", string.Format("{0}", CRC32.CheckSumBytes(buffer, cnt)));
                postArgs.Stream.Seek(0, SeekOrigin.Begin);
            }
            httpManager.FileContentType = PostFileType.STREAM;
            upload(httpManager, postArgs, key, token, uploadOptions, completionCallback);
        }
 
        private void upload(HttpManager httpManager, PostArgs postArgs, string key, string token,
            UploadOptions uploadOptions, CompletionCallback completionCallback)
        {
            //set key
            if (!string.IsNullOrEmpty(key))
            {
                postArgs.Params.Add("key", key);
            }
            //set token
            postArgs.Params.Add("token", token);
            //set mimeType
            string mimeType = "application/octet-stream";
            if (uploadOptions != null && !string.IsNullOrEmpty(uploadOptions.MimeType))
            {
                mimeType = uploadOptions.MimeType;
            }
            postArgs.MimeType = mimeType;
            //set extra params
            if (uploadOptions != null && uploadOptions.ExtraParams != null)
            {
                foreach (KeyValuePair<string, string> kvp in uploadOptions.ExtraParams)
                {
                    postArgs.Params.Add(kvp.Key, kvp.Value);
                }
            }
            //set progress callback and cancellation callback
            if (uploadOptions != null)
            {
                httpManager.ProgressCallback = uploadOptions.ProgressCallback;
                httpManager.CancellationCallback = uploadOptions.CancellationCallback;
{'fraction_non_alphanumeric': 0.088911377764927, 'fraction_numerical': 0.005782853838369235, 'mean_word_length': 1.8504326328800988, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1193314', 'n_tokens_mistral': 1724, 'n_tokens_neox': 1664, 'n_words': 404}