• filefunc.pas


    /// <author>cxg 2020-9-29</author>
    
    unit filefunc;
    
    interface
    
    uses
      Classes, ulog, serial, uGlobal, SysUtils;
    
    function downfile(const params: RawByteString): RawByteString;
    
    function upfile(const params: RawByteString): RawByteString;
    
    implementation
    
    function downfile(const params: RawByteString): RawByteString;
    var
      requ: TSerial;
      filename: string;
      fs: TFileStream;
    begin
      requ := TSerial.Create;
      fs := TFileStream.Create(DownPath + filename, fmOpenRead or fmShareExclusive);
      try
        try
          requ.loadFromRawByteString(params);
          filename := requ.force('filename').AsString;
          requ.clear;
          requ.force('return').AsBoolean := true;
          requ.force('file').AsStream := fs;
          Result := requ.saveToRawByteString;
        except
          on e: Exception do
          begin
            requ.clear;
            requ.force('return').AsBoolean := False;
            requ.force('err').AsString := e.Message;
            Result := requ.saveToRawByteString;
            Log.WriteLog('filefunc.downfile ' + e.Message);
          end;
        end;
      finally
        requ.Free;
        fs.Free;
      end;
    end;
    
    function upfile(const params: RawByteString): RawByteString;
    var
      requ: TSerial;
      filename: string;
      ms: TStream;
    begin
      requ := TSerial.Create;
      ms := TMemoryStream.Create;
      try
        try
          requ.loadFromRawByteString(params);
          filename := requ.force('filename').AsString;
          ForceDirectories(UpPath);
          ms := requ.force('file').AsStream;
          TMemoryStream(ms).SaveToFile(UpPath + filename);
          requ.clear;
          requ.force('return').AsBoolean := true;
          Result := requ.saveToRawByteString;
        except
          on e: Exception do
          begin
            requ.clear;
            requ.force('return').AsBoolean := False;
            Result := requ.saveToRawByteString;
            Log.WriteLog('filefunc.upfile ' + e.Message);
          end;
        end;  
      finally
        requ.Free;
        ms.Free;
      end;   
    end;
    
    end.
    

      

  • 相关阅读:
    GRUB引导Win8,Win7,Ubuntu
    The vim syntax of systemd unit file
    Win8蓝屏(WHEA_UNCORRECTABLE_ERROR)
    C#生成Excel
    IE中使用IFrame或Frameset导致session丢失的问题
    Apache 配置详解 ( 最好的 APACHE 配置教程 )
    关于(enctype="multipart/formdata") post 提交时中文乱码解决方案(使用jspsmartupload时)
    Java获取当前时间
    windows中定时操作(SetTimer函数用法)
    _RecordsetPtr的 open函数
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/13751283.html
Copyright © 2020-2023  润新知