public ReadContentFromStream ( |
||
binary | ||
리턴 | bool |
public List <FileRecord> Read(string filename) { var list = new List <FileRecord>(); int version = 1; if (!System.IO.File.Exists(filename)) { return(list); } using (var fs = System.IO.File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var reader = new BinaryReader(fs)) { while (fs.Position < fs.Length) { try { var record = new FileRecord(version); record.ReadContentFromStream(reader); list.Add(record); version++; } catch (IOException) { } } } } return(list); }
public async Task <DataWithVersion[]> ReadRecords(string streamName, long afterVersion, int maxCount) { var stream = this.options.ReadStream(streamName); if (!stream.CanRead || stream.Length == 0) { return(new DataWithVersion[0]); } int version = 1; var list = new List <FileRecord>(); var reader = new BinaryReader(stream); while (stream.Position < stream.Length) { try { var record = new FileRecord(version); record.ReadContentFromStream(reader); list.Add(record); version++; } catch (IOException) { } } if (this.options.AfterRead != null) { await this.options.AfterRead(stream); } return(list.Where(x => x.Name.Equals(streamName) && x.Version > afterVersion).Take(maxCount).Select(x => new DataWithVersion(x.Version, x.Bytes)).ToArray()); }
public async Task <DataWithName[]> ReadRecords(long afterVersion, int maxCount) { var stream = this.options.ReadStreamAll(); if (!stream.CanRead || stream.Length == 0) { if (this.options.AfterRead != null) { await this.options.AfterRead(stream); } return(new DataWithName[0]); } int version = 1; var list = new List <DataWithName>(); var reader = new BinaryReader(stream); while (stream.Position < stream.Length) { try { var record = new FileRecord(version); record.ReadContentFromStream(reader); list.Add(new DataWithName(record.Name, record.Bytes)); version++; } catch (IOException) { } } if (this.options.AfterRead != null) { await this.options.AfterRead(stream); } return(list.Skip((int)afterVersion).Take(maxCount).ToArray()); }
public List<FileRecord> Read(string filename) { var list = new List<FileRecord>(); int version = 1; if (!System.IO.File.Exists(filename)) { return list; } using (var fs = System.IO.File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var reader = new BinaryReader(fs)) { while (fs.Position < fs.Length) { try { var record = new FileRecord(version); record.ReadContentFromStream(reader); list.Add(record); version++; } catch (IOException) { } } } } return list; }
private static async Task<List<FileRecord>> ReadStreamToRecords(CloudAppendBlob blob) { List<FileRecord> records = new List<FileRecord>(); using (var s = new MemoryStream()) { if (!await blob.ExistsAsync()) { return records; } await blob.DownloadRangeToStreamAsync(s, 0, blob.Properties.Length); s.Position = 0; var reader = new BinaryReader(s); var record = new FileRecord(); while (record.ReadContentFromStream(reader)) { records.Add(record); record = new FileRecord(); } } return records; }