求php和.net双性大牛帮转译一段代码
小弟不才,研究了好久也搞不定。实在没办法请php和.net都牛得大师帮我翻译一下,最近在做FLASH在线录音,找了一个代码上传部分是php得。想请大师帮我改一下成.net版得。
<?php
$data = $GLOBALS[HTTP_RAW_POST_DATA];
if(empty($data)) {
$data = file_get_contents('php://input');
}
if($data){
$file = fopen(time().'.wav','w');//打开文件准备写入
$data = gzuncompress($data);
fwrite($file,$data);//写入
fclose($file);//关闭
echo "ok~~~";
}else echo 'Failed';
var ms = new MemoryStream();
Request.InputStream.CopyTo(ms);
var data = ms.ToArray();
if (data.Length > 0)
{
var time = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
FileStream fs = new FileStream(time + ".wav", FileMode.Create);
var gzip = new GZipStream(new MemoryStream(data), CompressionMode.Decompress);
gzip.CopyTo(fs);
gzip.Close();
fs.Close();
Response.Write("ok~~~");
}
else
Response.Write("failed");
// 假设只有一个文件上传
HttpPostedFile postedFile = HttpContext.Current.Request.Files[0];
// #4是复制到一个新的内存流,这里直接使用原始流
Stream compressedStream = postedFile.InputStream;
using (MemoryStream decompressStream = new MemoryStream()) {
using (GZipStream gzip = new GZipStream(compressedStream, CompressionMode.Decompress, true)) {
byte[] buffer = new byte[1024];
int offset = 0;
while ((offset = gzip.Read(buffer, 0, buffer.Length)) > 0) {
decompressStream.Write(buffer, 0, offset);
}
buffer = null;
}
decompressStream.Position = 0;
var time = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
string outputFilePath = Path.Combine(Server.MapPath("~/"), time.ToString() + ".wav");
File.WriteAllBytes(outputFilePath, decompressStream.ToArray());
}