Skip to content

Commit

Permalink
copy buffer before showing
Browse files Browse the repository at this point in the history
  • Loading branch information
xupefei committed Mar 6, 2018
1 parent aba242d commit 56b86ff
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ private void LoadFileAsync(string path)
{
const int maxLength = 50 * 1024 * 1024;
var buffer = new MemoryStream();
bool tooLong;
using (var s = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
tooLong = s.Length > maxLength;
while (s.Position < s.Length && buffer.Length < maxLength)
{
if (_disposed)
Expand All @@ -115,12 +117,16 @@ private void LoadFileAsync(string path)
if (_disposed)
return;
_context.Title += " (0 ~ 50MB)";
if (tooLong)
_context.Title += " (0 ~ 50MB)";
var encoding = CharsetDetector.DetectFromBytes(buffer.GetBuffer()).Detected?.Encoding ??
var bufferCopy = buffer.ToArray();
buffer.Dispose();
var encoding = CharsetDetector.DetectFromBytes(bufferCopy).Detected?.Encoding ??
Encoding.Default;
var doc = new TextDocument(encoding.GetString(buffer.GetBuffer()));
var doc = new TextDocument(encoding.GetString(bufferCopy));
doc.SetOwnerThread(Dispatcher.Thread);
if (_disposed)
Expand Down

0 comments on commit 56b86ff

Please sign in to comment.