Filesharing Service Fetch File Task¤
task api name:
fetch_file
The fetch_file task streams a file from the File Sharing worker to the client in chunks with offset support. This enables efficient downloading of large files with resume capability. The task is typically called through the client helper method NFPClient.fetch_file() which handles the streaming protocol, caching, and local file management automatically.
Using it from Python¤
from norfab.core.nfapi import NorFab
with NorFab(inventory="./inventory.yaml") as nf:
client = nf.make_client()
# Download file (recommended way - uses client helper)
ret = client.fetch_file(url="nf://filesharing/test_file_1.txt")
local_path = ret["content"]
print(local_path)
# Download and read content as text
ret = client.fetch_file(url="nf://filesharing/test_file_1.txt", read=True)
print(ret["content"]) # text content
# Direct task invocation (not recommended - use client helper instead)
reply = client.run_job(
service="filesharing",
task="fetch_file",
workers="any",
kwargs={
"url": "nf://filesharing/test_file_1.txt",
"chunk_size": 256000,
"offset": 0,
},
)
print(reply)
Using it from nfcli¤
NORFAB CLI exposes File Sharing under the file command group.
nf#man tree file.copy
root
└── file: File sharing service
└── copy: Copy files
├── url: File location, default 'nf://'
├── destination: File location to save downloaded content
└── read: Print file content, default 'False'
nf#
API Reference¤
Fetch a file in chunks with offset support.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
URL path starting with 'nf://' to fetch file from |
required |
chunk_size
|
int
|
Size of chunk to read in bytes (default: 256KB) |
256000
|
offset
|
int
|
Number of bytes to offset (default: 0) |
0
|
Returns:
| Type | Description |
|---|---|
Result
|
Result containing file chunk bytes or error message |
Source code in norfab\workers\filesharing_worker\filesharing_worker.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |