Kinetica   C#   API  Version 7.2.3.1
KineticaFileHandler.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.IO;
4 using System.Linq;
5 using System.Threading.Tasks;
6 using Microsoft.Extensions.FileSystemGlobbing;
7 using Microsoft.Extensions.FileSystemGlobbing.Abstractions;
8 
9 namespace kinetica.FileSystem;
10 
26  public class KineticaFileHandler
27  {
31  public const string KifsPathSeparator = "/";
32 
36  public const string KifsPathPrefix = "kifs://";
37 
41  public const string RemoteUserHomeDirPrefix = "~";
42 
47  public const long DefaultFileSizeToSplit = 62914560; // 60 MB
48 
52  public const int DefaultThreadPoolSize = 5;
53 
54  private readonly Kinetica _db;
55  private readonly Options _options;
56 
61  public KineticaFileHandler(Kinetica db) : this(db, new Options())
62  {
63  }
64 
70  public KineticaFileHandler(Kinetica db, Options options)
71  {
72  _db = db ?? throw new ArgumentNullException(nameof(db));
73  _options = options ?? new Options();
74  }
75 
79  public Options FileHandlerOptions => _options;
80 
81  #region Upload Methods
82 
88  public void Upload(string fileName, string remoteDirName)
89  {
90  Upload(fileName, remoteDirName, UploadOptions.Default, null);
91  }
92 
100  public void Upload(string fileName, string remoteDirName, UploadOptions? uploadOptions, IFileUploadListener? callback)
101  {
102  Upload(new List<string> { fileName }, remoteDirName, uploadOptions, callback);
103  }
104 
110  public void Upload(IList<string> fileNames, string remoteDirName)
111  {
112  Upload(fileNames, remoteDirName, UploadOptions.Default, null);
113  }
114 
122  public void Upload(IList<string> fileNames, string remoteDirName, UploadOptions? uploadOptions, IFileUploadListener? callback)
123  {
124  if (fileNames == null || fileNames.Count == 0)
125  throw new KineticaException("List of local files to upload cannot be null or empty");
126 
127  if (string.IsNullOrEmpty(remoteDirName))
128  throw new KineticaException("Remote directory name cannot be null or empty");
129 
130  if (!KifsDirectoryExists(remoteDirName))
131  throw new KineticaException($"Remote directory '{remoteDirName}' does not exist");
132 
133  uploadOptions ??= UploadOptions.Default;
134 
135  // Resolve glob patterns and validate files exist
136  var resolvedFiles = new List<string>();
137  foreach (var fileName in fileNames)
138  {
139  if (string.IsNullOrEmpty(fileName))
140  throw new KineticaException("File name cannot be null or empty");
141 
142  var files = ResolveLocalFiles(fileName, uploadOptions.Recursive);
143  if (files.Count == 0)
144  throw new KineticaException($"No files found matching pattern: {fileName}");
145 
146  resolvedFiles.AddRange(files);
147  }
148 
149  // Separate files into full-file uploads and multi-part uploads based on size
150  var fullFiles = new List<(string localPath, string remotePath)>();
151  var multiPartFiles = new List<(string localPath, string remotePath)>();
152 
153  foreach (var localPath in resolvedFiles)
154  {
155  var fileInfo = new FileInfo(localPath);
156  var remotePath = BuildRemotePath(remoteDirName, fileInfo.Name);
157 
158  if (fileInfo.Length <= _options.FileSizeToSplit)
159  {
160  fullFiles.Add((localPath, remotePath));
161  }
162  else
163  {
164  multiPartFiles.Add((localPath, remotePath));
165  }
166  }
167 
168  // Upload full files in batches
169  if (fullFiles.Count > 0)
170  {
171  UploadFullFiles(fullFiles, uploadOptions, callback);
172  }
173 
174  // Upload multi-part files
175  foreach (var (localPath, remotePath) in multiPartFiles)
176  {
177  UploadMultiPartFile(localPath, remotePath, uploadOptions, callback);
178  }
179  }
180 
188  public async Task UploadAsync(IList<string> fileNames, string remoteDirName, UploadOptions? uploadOptions = null, IFileUploadListener? callback = null)
189  {
190  await Task.Run(() => Upload(fileNames, remoteDirName, uploadOptions, callback));
191  }
192 
193  private void UploadFullFiles(IList<(string localPath, string remotePath)> files, UploadOptions options, IFileUploadListener? callback)
194  {
195  // Batch files for upload
196  var batch = new List<string>();
197  var batchData = new List<byte[]>();
198 
199  foreach (var (localPath, remotePath) in files)
200  {
201  try
202  {
203  var data = File.ReadAllBytes(localPath);
204  batch.Add(remotePath);
205  batchData.Add(data);
206 
207  // Upload batch when it reaches the threshold or total size limit
208  if (batch.Count >= _options.MaxFilesPerBatch)
209  {
210  ExecuteUploadBatch(batch, batchData, options, callback);
211  batch.Clear();
212  batchData.Clear();
213  }
214  }
215  catch (IOException ex)
216  {
217  throw new KineticaException($"Error reading file '{localPath}': {ex.Message}", ex);
218  }
219  }
220 
221  // Upload remaining files
222  if (batch.Count > 0)
223  {
224  ExecuteUploadBatch(batch, batchData, options, callback);
225  }
226  }
227 
228  private void ExecuteUploadBatch(IList<string> fileNames, IList<byte[]> fileData, UploadOptions options, IFileUploadListener? callback)
229  {
230  var requestOptions = new Dictionary<string, string>();
231 
232  if (options.Ttl > 0)
233  {
234  requestOptions["ttl"] = options.Ttl.ToString();
235  }
236 
237  if (options.DeleteIfExists)
238  {
240  }
241 
242  var request = new UploadFilesRequest(fileNames, fileData, requestOptions);
243  _db.uploadFiles(request);
244 
245  // Notify callback
246  if (callback != null)
247  {
248  var result = new FileOperationResult
249  {
250  FileNames = fileNames,
251  IsSuccessful = true,
252  OpMode = OperationMode.Upload,
253  IsMultiPart = false
254  };
255  callback.OnFullFileUpload(result);
256  }
257  }
258 
259  private void UploadMultiPartFile(string localPath, string remotePath, UploadOptions options, IFileUploadListener? callback)
260  {
261  var fileInfo = new FileInfo(localPath);
262  var uuid = Guid.NewGuid().ToString();
263  var partSize = _options.FileSizeToSplit;
264  var totalParts = (int)Math.Ceiling((double)fileInfo.Length / partSize);
265  var results = new List<FileOperationResult>();
266 
267  try
268  {
269  // Initialize multi-part upload
270  var initOptions = new Dictionary<string, string>
271  {
274  };
275 
276  if (options.DeleteIfExists)
277  {
279  }
280 
281  var initRequest = new UploadFilesRequest(
282  new List<string> { remotePath },
283  new List<byte[]>(),
284  initOptions);
285  _db.uploadFiles(initRequest);
286 
287  // Upload parts
288  using var stream = File.OpenRead(localPath);
289  var buffer = new byte[partSize];
290 
291  for (int partNumber = 1; partNumber <= totalParts; partNumber++)
292  {
293  var bytesRead = stream.Read(buffer, 0, buffer.Length);
294  var partData = new byte[bytesRead];
295  Array.Copy(buffer, partData, bytesRead);
296 
297  var partOptions = new Dictionary<string, string>
298  {
302  };
303 
304  var partRequest = new UploadFilesRequest(
305  new List<string> { remotePath },
306  new List<byte[]> { partData },
307  partOptions);
308  _db.uploadFiles(partRequest);
309 
310  // Notify callback
311  var partResult = new FileOperationResult
312  {
313  FileName = remotePath,
314  IsSuccessful = true,
315  OpMode = OperationMode.Upload,
316  IsMultiPart = true,
317  UploadInfo = new MultiPartUploadInfo
318  {
319  UploadUuid = uuid,
320  PartNumber = partNumber,
321  TotalParts = totalParts,
322  PartSize = bytesRead
323  }
324  };
325  results.Add(partResult);
326  callback?.OnPartUpload(partResult);
327  }
328 
329  // Complete multi-part upload
330  var completeOptions = new Dictionary<string, string>
331  {
334  };
335 
336  var completeRequest = new UploadFilesRequest(
337  new List<string> { remotePath },
338  new List<byte[]>(),
339  completeOptions);
340  _db.uploadFiles(completeRequest);
341 
342  callback?.OnMultiPartUploadComplete(results);
343  }
344  catch (Exception ex)
345  {
346  // Cancel multi-part upload on error
347  try
348  {
349  var cancelOptions = new Dictionary<string, string>
350  {
353  };
354 
355  var cancelRequest = new UploadFilesRequest(
356  new List<string> { remotePath },
357  new List<byte[]>(),
358  cancelOptions);
359  _db.uploadFiles(cancelRequest);
360  }
361  catch
362  {
363  // Ignore cancel errors
364  }
365 
366  throw new KineticaException($"Failed to upload file '{localPath}': {ex.Message}", ex);
367  }
368  }
369 
370  #endregion
371 
372  #region Download Methods
373 
379  public void Download(string fileName, string localDirName)
380  {
381  Download(fileName, localDirName, DownloadOptions.Default, null);
382  }
383 
391  public void Download(string fileName, string localDirName, DownloadOptions? downloadOptions, IFileDownloadListener? callback)
392  {
393  Download(new List<string> { fileName }, localDirName, downloadOptions, callback);
394  }
395 
401  public void Download(IList<string> fileNames, string localDirName)
402  {
403  Download(fileNames, localDirName, DownloadOptions.Default, null);
404  }
405 
413  public void Download(IList<string> fileNames, string localDirName, DownloadOptions? downloadOptions, IFileDownloadListener? callback)
414  {
415  if (fileNames == null || fileNames.Count == 0)
416  throw new KineticaException("List of KiFS file names cannot be null or empty");
417 
418  if (string.IsNullOrEmpty(localDirName))
419  throw new KineticaException("Local directory name cannot be null or empty");
420 
421  if (!Directory.Exists(localDirName))
422  throw new KineticaException($"Local directory '{localDirName}' does not exist");
423 
424  downloadOptions ??= DownloadOptions.Default;
425 
426  // Download files
427  var request = new DownloadFilesRequest(fileNames, new List<long>(), new List<long>());
428  var response = _db.downloadFiles(request);
429 
430  // Write files to local directory
431  var downloadedFiles = new List<string>();
432  for (int i = 0; i < response.file_names.Count; i++)
433  {
434  var remoteName = response.file_names[i];
435  var localFileName = Path.GetFileName(remoteName);
436  var localPath = Path.Combine(localDirName, localFileName);
437 
438  if (File.Exists(localPath) && !downloadOptions.OverwriteExisting)
439  {
440  throw new KineticaException($"File '{localPath}' already exists and OverwriteExisting is false");
441  }
442 
443  File.WriteAllBytes(localPath, response.file_data[i]);
444  downloadedFiles.Add(localPath);
445  }
446 
447  callback?.OnFullFileDownload(downloadedFiles);
448  }
449 
457  public void DownloadDirectory(string remoteDirName, string localDirName, DownloadOptions? downloadOptions = null, IFileDownloadListener? callback = null)
458  {
459  if (!Directory.Exists(localDirName))
460  throw new KineticaException($"Local directory '{localDirName}' does not exist");
461 
462  var showFilesResponse = _db.showFiles(new List<string> { remoteDirName }, new Dictionary<string, string>());
463 
464  if (showFilesResponse.file_names.Count > 0)
465  {
466  Download(showFilesResponse.file_names, localDirName, downloadOptions, callback);
467  }
468  }
469 
477  public async Task DownloadAsync(IList<string> fileNames, string localDirName, DownloadOptions? downloadOptions = null, IFileDownloadListener? callback = null)
478  {
479  await Task.Run(() => Download(fileNames, localDirName, downloadOptions, callback));
480  }
481 
482  #endregion
483 
484  #region Directory Operations
485 
490  public void CreateDirectory(string remoteDirName)
491  {
492  CreateDirectory(remoteDirName, true);
493  }
494 
500  public void CreateDirectory(string remoteDirName, bool noErrorIfExists)
501  {
502  var options = new Dictionary<string, string>
503  {
507  };
508 
509  _db.createDirectory(remoteDirName, options);
510  }
511 
516  public void DeleteDirectory(string remoteDirName)
517  {
518  DeleteDirectory(remoteDirName, true, true);
519  }
520 
527  public void DeleteDirectory(string remoteDirName, bool recursive, bool noErrorIfNotExists)
528  {
529  var options = new Dictionary<string, string>
530  {
537  };
538 
539  _db.deleteDirectory(remoteDirName, options);
540  }
541 
547  public IList<KifsDirectoryInfo> ShowDirectories(IList<string> remoteDirNames)
548  {
549  if (remoteDirNames == null || remoteDirNames.Count == 0)
550  throw new KineticaException("List of KiFS directory names cannot be null or empty");
551 
552  var result = new List<KifsDirectoryInfo>();
553 
554  foreach (var dirName in remoteDirNames)
555  {
556  if (string.IsNullOrEmpty(dirName?.Trim()))
557  throw new KineticaException("Directory name cannot be null or empty");
558 
559  var response = _db.showDirectories(dirName, new Dictionary<string, string>());
560 
561  for (int i = 0; i < response.directories.Count; i++)
562  {
563  result.Add(new KifsDirectoryInfo
564  {
565  KifsPath = response.directories[i],
566  CreatedBy = response.users[i],
567  Permission = response.permissions[i],
568  CreationTime = response.creation_times[i]
569  });
570  }
571  }
572 
573  return result;
574  }
575 
581  public IList<KifsDirectoryInfo> ShowDirectory(string remoteDirName)
582  {
583  if (string.IsNullOrEmpty(remoteDirName))
584  throw new KineticaException("KiFS directory name cannot be null or empty");
585 
586  var response = _db.showDirectories(remoteDirName, new Dictionary<string, string>());
587  var result = new List<KifsDirectoryInfo>();
588 
589  for (int i = 0; i < response.directories.Count; i++)
590  {
591  result.Add(new KifsDirectoryInfo
592  {
593  KifsPath = response.directories[i],
594  CreatedBy = response.users[i],
595  Permission = response.permissions[i],
596  CreationTime = response.creation_times[i]
597  });
598  }
599 
600  return result;
601  }
602 
607  public IList<KifsDirectoryInfo> ShowAllDirectories()
608  {
609  var response = _db.showDirectories("", new Dictionary<string, string>());
610  var result = new List<KifsDirectoryInfo>();
611 
612  for (int i = 0; i < response.directories.Count; i++)
613  {
614  result.Add(new KifsDirectoryInfo
615  {
616  KifsPath = response.directories[i],
617  CreatedBy = response.users[i],
618  Permission = response.permissions[i],
619  CreationTime = response.creation_times[i]
620  });
621  }
622 
623  return result;
624  }
625 
626  #endregion
627 
628  #region File Operations
629 
634  public void DeleteFiles(IList<string> fileNames)
635  {
636  DeleteFiles(fileNames, true);
637  }
638 
644  public void DeleteFiles(IList<string> fileNames, bool noErrorIfNotExists)
645  {
646  var options = new Dictionary<string, string>
647  {
648  [DeleteFilesRequest.Options.NO_ERROR_IF_NOT_EXISTS] = noErrorIfNotExists
651  };
652 
653  _db.deleteFiles(fileNames, options);
654  }
655 
660  public void DeleteFilesInDirectory(string remoteDirName)
661  {
662  DeleteFilesInDirectory(remoteDirName, true);
663  }
664 
670  public void DeleteFilesInDirectory(string remoteDirName, bool noErrorIfNotExists)
671  {
672  var showFilesResponse = _db.showFiles(new List<string> { remoteDirName }, new Dictionary<string, string>());
673  DeleteFiles(showFilesResponse.file_names, noErrorIfNotExists);
674  }
675 
681  public IList<KifsFileInfo> ShowFiles(IList<string> remotePaths)
682  {
683  if (remotePaths == null || remotePaths.Count == 0)
684  throw new KineticaException("List of KiFS paths cannot be null or empty");
685 
686  var response = _db.showFiles(remotePaths, new Dictionary<string, string>());
687  var result = new List<KifsFileInfo>();
688 
689  for (int i = 0; i < response.file_names.Count; i++)
690  {
691  result.Add(new KifsFileInfo
692  {
693  FileName = response.file_names[i],
694  FileSize = response.sizes[i],
695  CreatedBy = response.users[i],
696  CreationTime = response.creation_times[i],
697  Info = response.info
698  });
699  }
700 
701  return result;
702  }
703 
704  #endregion
705 
706  #region Existence Checks
707 
713  public bool KifsDirectoryExists(string dirName)
714  {
715  if (string.IsNullOrEmpty(dirName))
716  return false;
717 
718  try
719  {
720  var response = _db.showDirectories(dirName, new Dictionary<string, string>());
721  return response.directories.Contains(dirName);
722  }
723  catch (KineticaException)
724  {
725  return false;
726  }
727  }
728 
734  public bool KifsDirectoriesExist(ISet<string> dirNames)
735  {
736  if (dirNames == null || dirNames.Count == 0)
737  return false;
738 
739  try
740  {
741  var response = _db.showDirectories("", new Dictionary<string, string>());
742  var existingDirs = new HashSet<string>(response.directories);
743  return dirNames.All(d => existingDirs.Contains(d));
744  }
745  catch (KineticaException)
746  {
747  return false;
748  }
749  }
750 
756  public bool KifsFileExists(string fileName)
757  {
758  if (string.IsNullOrEmpty(fileName))
759  return false;
760 
761  try
762  {
763  var response = _db.showFiles(new List<string> { fileName }, new Dictionary<string, string>());
764  return response.file_names.Contains(fileName);
765  }
766  catch (KineticaException)
767  {
768  return false;
769  }
770  }
771 
772  #endregion
773 
774  #region Helper Methods
775 
776  private IList<string> ResolveLocalFiles(string pattern, bool recursive)
777  {
778  // Check if it's a glob pattern or a direct file path
779  if (!ContainsGlobCharacters(pattern))
780  {
781  if (File.Exists(pattern))
782  {
783  return new List<string> { Path.GetFullPath(pattern) };
784  }
785  return new List<string>();
786  }
787 
788  // Use glob matching
789  var matcher = new Matcher();
790 
791  // Get the base directory and the pattern
792  var (baseDir, globPattern) = SplitPathAndPattern(pattern);
793 
794  if (recursive)
795  {
796  matcher.AddInclude("**/" + globPattern);
797  }
798  else
799  {
800  matcher.AddInclude(globPattern);
801  }
802 
803  var directoryInfo = new DirectoryInfo(baseDir);
804  if (!directoryInfo.Exists)
805  {
806  return new List<string>();
807  }
808 
809  var result = matcher.Execute(new DirectoryInfoWrapper(directoryInfo));
810  return result.Files.Select(f => Path.GetFullPath(Path.Combine(baseDir, f.Path))).ToList();
811  }
812 
813  private static bool ContainsGlobCharacters(string path)
814  {
815  return path.Contains('*') || path.Contains('?') || path.Contains('[');
816  }
817 
818  private static (string baseDir, string pattern) SplitPathAndPattern(string path)
819  {
820  var normalizedPath = path.Replace('\\', '/');
821  var lastSeparatorBeforeGlob = -1;
822 
823  for (int i = 0; i < normalizedPath.Length; i++)
824  {
825  char c = normalizedPath[i];
826  if (c == '*' || c == '?' || c == '[')
827  break;
828  if (c == '/')
829  lastSeparatorBeforeGlob = i;
830  }
831 
832  if (lastSeparatorBeforeGlob < 0)
833  {
834  return (Directory.GetCurrentDirectory(), normalizedPath);
835  }
836 
837  return (normalizedPath.Substring(0, lastSeparatorBeforeGlob), normalizedPath.Substring(lastSeparatorBeforeGlob + 1));
838  }
839 
840  private static string BuildRemotePath(string remoteDirName, string fileName)
841  {
842  if (remoteDirName.EndsWith(KifsPathSeparator))
843  {
844  return remoteDirName + fileName;
845  }
846  return remoteDirName + KifsPathSeparator + fileName;
847  }
848 
849  #endregion
850 
851  #region Options Class
852 
856  public class Options
857  {
863  public long FileSizeToSplit { get; set; } = DefaultFileSizeToSplit;
864 
869  public int ThreadPoolSize { get; set; } = DefaultThreadPoolSize;
870 
875  public int MaxFilesPerBatch { get; set; } = 100;
876 
880  public Options()
881  {
882  }
883 
888  public Options(Options other)
889  {
893  }
894 
900  public Options SetFileSizeToSplit(long size)
901  {
902  if (size <= 0 || size > DefaultFileSizeToSplit)
903  throw new KineticaException($"FileSizeToSplit must be between 1 and {DefaultFileSizeToSplit}");
904  FileSizeToSplit = size;
905  return this;
906  }
907 
913  public Options SetThreadPoolSize(int size)
914  {
915  if (size <= 0 || size > Environment.ProcessorCount)
916  throw new KineticaException($"ThreadPoolSize must be between 1 and {Environment.ProcessorCount}");
917  ThreadPoolSize = size;
918  return this;
919  }
920  }
921 
922  #endregion
923  }
int ThreadPoolSize
Gets or sets the thread pool size for concurrent file operations.
OperationMode
Indicates the type of file operation.
const string NO_ERROR_IF_NOT_EXISTS
If TRUE, no error is returned if a specified file does not exist.
Definition: DeleteFiles.cs:36
const string NO_ERROR_IF_EXISTS
If TRUE, does not return an error if the directory already exists.
void Upload(IList< string > fileNames, string remoteDirName)
Uploads multiple files to a KiFS directory using default options.
const long DefaultFileSizeToSplit
Default file size threshold for multi-part uploads (60 MB).
Options SetThreadPoolSize(int size)
Sets the thread pool size for concurrent file operations.
static DownloadOptions Default
Returns the default download options.
bool KifsFileExists(string fileName)
Checks whether a KiFS file exists.
bool KifsDirectoriesExist(ISet< string > dirNames)
Checks whether multiple KiFS directories exist.
Interface for receiving callbacks during file upload operations.
Main class for handling file operations with Kinetica's KiFS (Kinetica File System).
void DeleteFilesInDirectory(string remoteDirName, bool noErrorIfNotExists)
Deletes all files in a KiFS directory.
void DeleteFilesInDirectory(string remoteDirName)
Deletes all files in a KiFS directory.
KineticaFileHandler(Kinetica db, Options options)
Constructs a KineticaFileHandler with the specified Kinetica connection and options.
bool DeleteIfExists
Gets or sets whether to delete existing files before uploading.
void Download(IList< string > fileNames, string localDirName)
Downloads multiple files from KiFS to a local directory using default options.
const string RECURSIVE
If TRUE, will delete directory and all files residing in it.
void Upload(IList< string > fileNames, string remoteDirName, UploadOptions? uploadOptions, IFileUploadListener? callback)
Uploads multiple files to a KiFS directory.
bool OverwriteExisting
Gets or sets whether to overwrite existing files on the local file system.
const int DefaultThreadPoolSize
Default thread pool size for file operations.
void OnFullFileUpload(FileOperationResult result)
Called when a full file upload (non-multi-part) has been completed.
const string CANCEL
Cancel the specified multipart file upload.
Definition: UploadFiles.cs:142
Options for uploading files to KiFS.
Definition: UploadOptions.cs:6
const string COMPLETE
Complete the specified multipart file upload.
Definition: UploadFiles.cs:139
void Upload(string fileName, string remoteDirName, UploadOptions? uploadOptions, IFileUploadListener? callback)
Uploads a single file to a KiFS directory.
A set of string constants for the parameter options.
const string UPLOAD_PART
Uploads a part of the specified multipart file upload.
Definition: UploadFiles.cs:136
const string DELETE_IF_EXISTS
If TRUE, any existing files specified in file_names will be deleted prior to start of upload.
Definition: UploadFiles.cs:167
A set of parameters for Kinetica.deleteFiles.
Definition: DeleteFiles.cs:16
Options(Options other)
Creates a copy of the specified options.
void CreateDirectory(string remoteDirName, bool noErrorIfExists)
Creates a KiFS directory.
void OnFullFileDownload(IList< string > fileNames)
Called when one or more full file downloads (non-multi-part) have been completed.
void DeleteFiles(IList< string > fileNames)
Deletes files from KiFS, suppressing error if files don't exist.
const string MULTIPART_UPLOAD_PART_NUMBER
Incremental part number for each part in a multipart upload.
Definition: UploadFiles.cs:151
void DeleteDirectory(string remoteDirName, bool recursive, bool noErrorIfNotExists)
Deletes a KiFS directory.
IList< KifsDirectoryInfo > ShowAllDirectories()
Returns statistics about all KiFS directories.
void Download(string fileName, string localDirName, DownloadOptions? downloadOptions, IFileDownloadListener? callback)
Downloads a single file from KiFS to a local directory.
async Task UploadAsync(IList< string > fileNames, string remoteDirName, UploadOptions? uploadOptions=null, IFileUploadListener? callback=null)
Uploads files asynchronously to a KiFS directory.
const string KifsPathPrefix
Prefix to use when referencing KiFS files (e.g., for file ingest).
const string MULTIPART_OPERATION
Multipart upload operation to perform.
Definition: UploadFiles.cs:129
void Download(IList< string > fileNames, string localDirName, DownloadOptions? downloadOptions, IFileDownloadListener? callback)
Downloads multiple files from KiFS to a local directory.
const string KifsPathSeparator
Separator character between a KiFS directory and file name.
bool KifsDirectoryExists(string dirName)
Checks whether a KiFS directory exists.
Options FileHandlerOptions
Gets the options for this file handler.
void Upload(string fileName, string remoteDirName)
Uploads a single file to a KiFS directory using default options.
Options for configuring the KineticaFileHandler behavior.
Options SetFileSizeToSplit(long size)
Sets the file size threshold for multi-part uploads.
Options()
Creates a new Options instance with default values.
KineticaFileHandler(Kinetica db)
Constructs a KineticaFileHandler with the specified Kinetica connection.
void DeleteFiles(IList< string > fileNames, bool noErrorIfNotExists)
Deletes files from KiFS.
void Download(string fileName, string localDirName)
Downloads a single file from KiFS to a local directory using default options.
int MaxFilesPerBatch
Gets or sets the maximum number of files to upload in a single batch.
A set of string constants for the parameter options.
Definition: UploadFiles.cs:68
Interface for receiving callbacks during file download operations.
void OnMultiPartUploadComplete(IList< FileOperationResult > results)
Called when all parts of a multi-part upload have been completed.
const string NO_ERROR_IF_NOT_EXISTS
If TRUE, no error is returned if specified directory does not exist.
Options for downloading files from KiFS.
static UploadOptions Default
Returns the default upload options.
void DeleteDirectory(string remoteDirName)
Deletes a KiFS directory and all files under it, suppressing error if it doesn't exist.
A set of parameters for Kinetica.uploadFiles.
Definition: UploadFiles.cs:63
Contains information about a file stored in KiFS.
Definition: KifsFileInfo.cs:9
void CreateDirectory(string remoteDirName)
Creates a KiFS directory, suppressing error if it already exists.
Contains information about a multi-part upload operation.
void DownloadDirectory(string remoteDirName, string localDirName, DownloadOptions? downloadOptions=null, IFileDownloadListener? callback=null)
Downloads all files in a KiFS directory to a local directory.
async Task DownloadAsync(IList< string > fileNames, string localDirName, DownloadOptions? downloadOptions=null, IFileDownloadListener? callback=null)
Downloads files asynchronously from KiFS to a local directory.
A set of parameters for Kinetica.deleteDirectory.
A set of string constants for the parameter options.
IList< KifsDirectoryInfo > ShowDirectories(IList< string > remoteDirNames)
Returns statistics about the given KiFS directories.
const string RemoteUserHomeDirPrefix
Alias for a user's home directory.
A set of parameters for Kinetica.createDirectory.
const string MULTIPART_UPLOAD_UUID
UUID to uniquely identify a multipart upload.
Definition: UploadFiles.cs:145
int Ttl
Gets or sets the time-to-live (TTL) value for uploaded files in minutes.
IList< KifsFileInfo > ShowFiles(IList< string > remotePaths)
Returns statistics about the given KiFS files.
long FileSizeToSplit
Gets or sets the file size threshold for multi-part uploads in bytes.
Contains the result of a file upload or download operation.
IList< KifsDirectoryInfo > ShowDirectory(string remoteDirName)
Returns statistics about a single KiFS directory.
Contains information about a directory in KiFS.
void OnPartUpload(FileOperationResult result)
Called when a single part of a multi-part upload has been completed.
const string INIT
Initialize a multipart file upload.
Definition: UploadFiles.cs:132
A set of parameters for Kinetica.downloadFiles.
A set of string constants for the parameter options.
Definition: DeleteFiles.cs:21