public async Task <FileLoaderModel> GetFileBlock([FromBody] FileLoaderModel value) { try { string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FileLoad", value.FileName); using (FileStream fstream = File.Open(path, FileMode.Open)) { byte[] array = new byte[value.BlockSize]; fstream.Seek(value.Offset, SeekOrigin.Current); value.ByteReadCout = fstream.Read(array, 0, array.Length); value.Block = array; fstream.Close(); } return(value); } catch (FileNotFoundException e) { return(new FileLoaderModel()); } catch (Exception e) { return(new FileLoaderModel()); } }
public bool SaveFile(FileLoaderModel value) { string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, value.FileName); try { using (FileStream fstream = File.Open(path, FileMode.Append)) { fstream.Seek(value.Offset, SeekOrigin.Current); fstream.Write(value.Block, 0, value.BlockSize); fstream.Close(); } return(true); } catch (Exception e) { return(false); } return(false); }