1
0
Fork 0

- [kami] prevented reading entire file in memory when downloading.

This commit is contained in:
cage 2022-01-14 17:09:23 +01:00
parent edf970e5fc
commit a44e91322f
3 changed files with 20 additions and 18 deletions

View File

@ -205,8 +205,6 @@
(assert path)
(fs:recursive-delete path)))
(define-constant +download-buffer+ (expt 2 24) :test #'=)
(define-constant +octect-type+ '(unsigned-byte 8) :test #'equalp)
(defun make-temporary-file-from-path (path)
@ -217,6 +215,8 @@
(let ((path (tree-path (data node))))
(make-temporary-file-from-path path)))
(define-constant +download-buffer+ (expt 2 24) :test #'=)
(defun download-local-filesystem-node (matching-node
&optional
(destination-file
@ -413,10 +413,8 @@
(defun upload-treenode (window source-file remote-path)
(when-let* ((root-node (filesystem-root window))
(parent-node (find-node root-node (fs:parent-dir-path remote-path)))
(parent-path (tree-path (data parent-node)))
(destination-path (fs:append-file-to-path parent-path
(fs:path-last-element source-file))))
(funcall (filesystem-upload-function window) source-file destination-path)
(parent-path (tree-path (data parent-node))))
(funcall (filesystem-upload-function window) source-file remote-path)
(remove-all-children parent-node)
(expand-treenode window parent-path)
(win-clear window :redraw nil)

View File

@ -1,6 +1,6 @@
(in-package :kami)
(a:define-constant +download-buffer+ (expt 2 24) :test #'=)
(a:define-constant +download-buffer+ (expt 2 10) :test #'=)
(a:define-constant +octect-type+ '(unsigned-byte 8) :test #'equalp)
@ -98,14 +98,18 @@
(let* ((*stream* stream)
(*root-fid* root-fid)
(path (tree-path (data node))))
(with-cloned-root-fid (*stream* root-fid)
(let ((data (9p:slurp-file *stream* root-fid path)))
(with-open-file (output-stream destination-file
:direction :output
:if-exists :supersede
:if-does-not-exist :create
:element-type +octect-type+)
(write-sequence data output-stream)))))
(with-open-file (output-stream destination-file
:direction :output
:if-exists :supersede
:if-does-not-exist :create
:element-type +octect-type+)
(with-cloned-root-fid (*stream* root-fid)
(9p:read-entire-file-apply-function stream
root-fid
path
(lambda (data offset count)
(declare (ignore offset count))
(write-sequence data output-stream))))))
destination-file))
(defun upload-node (stream root-fid)
@ -116,8 +120,9 @@
:direction :input
:element-type +octect-type+)
(with-cloned-root-fid (*stream* root-fid)
(let* ((buffer (misc:make-array-frame +download-buffer+ 0 +octect-type+ t))
(fid (9p:create-path *stream* root-fid destination-path)))
(let* ((buffer (misc:make-array-frame +download-buffer+ 0 +octect-type+ t))
(fid (9p:create-path *stream* root-fid destination-path)))
(loop named write-loop
for read-so-far = (read-sequence buffer input-stream)
then (read-sequence buffer input-stream)

View File

@ -2029,7 +2029,6 @@
(:shadowing-import-from :misc :random-elt :shuffle)
(:export
:+octect-type+
:+download-buffer+
:make-temporary-file-from-node
:make-node-data
:filesystem-tree-window