Skip to content

Commit 94605f1

Browse files
committed
Write pulled data directly to the file instead of caching it
1 parent e4a9352 commit 94605f1

1 file changed

Lines changed: 14 additions & 17 deletions

File tree

nxc/protocols/nfs.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -281,27 +281,24 @@ def get_file(self):
281281
# Handle files over the default chunk size of 1024 * 1024
282282
offset = 0
283283
eof = False
284-
file_data_total = b''
285284

286285
# Loop until we have read the entire file
287-
while not eof:
288-
file_data = self.nfs3.read(file_handle, offset, chunk_count=1024 * 1024, auth=self.auth)
286+
with open(local_file_path, "wb+") as local_file:
287+
while not eof:
288+
file_data = self.nfs3.read(file_handle, offset, auth=self.auth)
289289

290-
if "resfail" in file_data:
291-
raise Exception("Insufficient Permissions")
290+
if "resfail" in file_data:
291+
raise Exception("Insufficient Permissions")
292292

293-
else:
294-
# Get the data and append it to the total file data
295-
data = file_data["resok"]["data"]
296-
eof = file_data["resok"]["eof"]
297-
file_data_total += data
298-
299-
# Update the offset to read the next chunk
300-
offset += len(data)
301-
302-
# Write the complete file data to the local file
303-
with open(local_file_path, "wb+") as local_file:
304-
local_file.write(file_data_total)
293+
else:
294+
# Get the data and append it to the total file data
295+
data = file_data["resok"]["data"]
296+
eof = file_data["resok"]["eof"]
297+
298+
# Update the offset to read the next chunk
299+
offset += len(data)
300+
# Write the file data to the local file
301+
local_file.write(data)
305302

306303
self.logger.highlight(f"File successfully downloaded to {local_file_path} from {remote_file_path}")
307304

0 commit comments

Comments
 (0)