mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 10:19:07 +00:00
copy buffer before showing
This commit is contained in:
@@ -98,9 +98,11 @@ namespace QuickLook.Plugin.TextViewer
|
|||||||
{
|
{
|
||||||
const int maxLength = 50 * 1024 * 1024;
|
const int maxLength = 50 * 1024 * 1024;
|
||||||
var buffer = new MemoryStream();
|
var buffer = new MemoryStream();
|
||||||
|
bool tooLong;
|
||||||
|
|
||||||
using (var s = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
using (var s = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||||
{
|
{
|
||||||
|
tooLong = s.Length > maxLength;
|
||||||
while (s.Position < s.Length && buffer.Length < maxLength)
|
while (s.Position < s.Length && buffer.Length < maxLength)
|
||||||
{
|
{
|
||||||
if (_disposed)
|
if (_disposed)
|
||||||
@@ -115,12 +117,16 @@ namespace QuickLook.Plugin.TextViewer
|
|||||||
if (_disposed)
|
if (_disposed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (tooLong)
|
||||||
_context.Title += " (0 ~ 50MB)";
|
_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;
|
Encoding.Default;
|
||||||
|
|
||||||
var doc = new TextDocument(encoding.GetString(buffer.GetBuffer()));
|
var doc = new TextDocument(encoding.GetString(bufferCopy));
|
||||||
doc.SetOwnerThread(Dispatcher.Thread);
|
doc.SetOwnerThread(Dispatcher.Thread);
|
||||||
|
|
||||||
if (_disposed)
|
if (_disposed)
|
||||||
|
Reference in New Issue
Block a user