Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::GZipFileSystem Class Reference
Inheritance diagram for duckdb::GZipFileSystem:
Collaboration diagram for duckdb::GZipFileSystem:

Public Member Functions

unique_ptr< FileHandleOpenCompressedFile (QueryContext context, unique_ptr< FileHandle > handle, bool write) override
 
std::string GetName () const override
 Return the name of the filesytem. Used for forming diagnosis messages.
 
unique_ptr< StreamWrapperCreateStream () override
 
idx_t InBufferSize () override
 
idx_t OutBufferSize () override
 
- Public Member Functions inherited from duckdb::CompressedFileSystem
DUCKDB_API int64_t Read (FileHandle &handle, void *buffer, int64_t nr_bytes) override
 
DUCKDB_API int64_t Write (FileHandle &handle, void *buffer, int64_t nr_bytes) override
 Write nr_bytes from the buffer into the file, moving the file pointer forward by nr_bytes.
 
DUCKDB_API void Reset (FileHandle &handle) override
 Reset a file to the beginning (equivalent to Seek(handle, 0) for simple files)
 
DUCKDB_API int64_t GetFileSize (FileHandle &handle) override
 Returns the file size of a file handle, returns -1 on error.
 
DUCKDB_API bool OnDiskFile (FileHandle &handle) override
 
DUCKDB_API bool CanSeek () override
 Whether or not we can seek into the file.
 
- Public Member Functions inherited from duckdb::FileSystem
virtual DUCKDB_API unique_ptr< FileHandleOpenFile (const string &path, FileOpenFlags flags, optional_ptr< FileOpener > opener=nullptr)
 
DUCKDB_API unique_ptr< FileHandleOpenFile (const OpenFileInfo &path, FileOpenFlags flags, optional_ptr< FileOpener > opener=nullptr)
 
virtual DUCKDB_API void Read (FileHandle &handle, void *buffer, int64_t nr_bytes, idx_t location)
 
virtual DUCKDB_API void Write (FileHandle &handle, void *buffer, int64_t nr_bytes, idx_t location)
 
virtual DUCKDB_API bool Trim (FileHandle &handle, idx_t offset_bytes, idx_t length_bytes)
 
virtual DUCKDB_API timestamp_t GetLastModifiedTime (FileHandle &handle)
 Returns the file last modified time of a file handle, returns timespec with zero on all attributes on error.
 
virtual DUCKDB_API string GetVersionTag (FileHandle &handle)
 
virtual DUCKDB_API FileType GetFileType (FileHandle &handle)
 Returns the file type of the attached handle.
 
virtual DUCKDB_API FileMetadata Stats (FileHandle &handle)
 Returns the file stats of the attached handle.
 
virtual DUCKDB_API void Truncate (FileHandle &handle, int64_t new_size)
 
virtual DUCKDB_API bool DirectoryExists (const string &directory, optional_ptr< FileOpener > opener=nullptr)
 Check if a directory exists.
 
virtual DUCKDB_API void CreateDirectory (const string &directory, optional_ptr< FileOpener > opener=nullptr)
 Create a directory if it does not exist.
 
virtual DUCKDB_API void CreateDirectoriesRecursive (const string &path, optional_ptr< FileOpener > opener=nullptr)
 Helper function that uses DirectoryExists and CreateDirectory to ensure all directories in path are created.
 
virtual DUCKDB_API void RemoveDirectory (const string &directory, optional_ptr< FileOpener > opener=nullptr)
 Recursively remove a directory and all files in it.
 
virtual DUCKDB_API bool ListFiles (const string &directory, const std::function< void(const string &, bool)> &callback, FileOpener *opener=nullptr)
 List files in a directory, invoking the callback method for each one with (filename, is_dir)
 
DUCKDB_API bool ListFiles (const string &directory, const std::function< void(OpenFileInfo &info)> &callback, optional_ptr< FileOpener > opener=nullptr)
 
virtual DUCKDB_API void MoveFile (const string &source, const string &target, optional_ptr< FileOpener > opener=nullptr)
 
virtual DUCKDB_API bool FileExists (const string &filename, optional_ptr< FileOpener > opener=nullptr)
 Check if a file exists.
 
virtual DUCKDB_API bool IsPipe (const string &filename, optional_ptr< FileOpener > opener=nullptr)
 Check if path is pipe.
 
virtual DUCKDB_API void RemoveFile (const string &filename, optional_ptr< FileOpener > opener=nullptr)
 Remove a file from disk.
 
virtual DUCKDB_API bool TryRemoveFile (const string &filename, optional_ptr< FileOpener > opener=nullptr)
 Remvoe a file from disk if it exists - if it does not exist, return false.
 
virtual DUCKDB_API void RemoveFiles (const vector< string > &filenames, optional_ptr< FileOpener > opener=nullptr)
 Remove multiple files from disk - does not error if any file does not exist.
 
virtual DUCKDB_API void FileSync (FileHandle &handle)
 Sync a file handle to disk.
 
virtual DUCKDB_API string GetHomeDirectory ()
 Gets the users home directory.
 
virtual DUCKDB_API string ExpandPath (const string &path)
 Expands a given path, including e.g. expanding the home directory of the user.
 
virtual DUCKDB_API string PathSeparator (const string &path)
 Path separator for path.
 
virtual DUCKDB_API bool IsPathAbsolute (const string &path)
 Checks if path is is an absolute path.
 
DUCKDB_API string JoinPath (const string &a, const string &path)
 Join two paths together.
 
template<typename... ARGS>
string JoinPath (const string &a, const string &b, ARGS... args)
 
DUCKDB_API string ConvertSeparators (const string &path)
 Convert separators in a path to the local separators (e.g. convert "/" into \ on windows)
 
DUCKDB_API string ExtractBaseName (const string &path)
 Extract the base name of a file (e.g. if the input is lib/example.dll the base name is 'example')
 
DUCKDB_API string ExtractExtension (const string &path)
 Extract the extension of a file (e.g. if the input is lib/example.dll the extension is 'dll')
 
DUCKDB_API string ExtractName (const string &path)
 Extract the name of a file (e.g if the input is lib/example.dll the name is 'example.dll')
 
virtual DUCKDB_API vector< OpenFileInfoGlob (const string &path, FileOpener *opener=nullptr)
 Runs a glob on the file system, returning a list of matching files.
 
DUCKDB_API unique_ptr< MultiFileListGlob (const string &path, const FileGlobInput &input, optional_ptr< FileOpener > opener)
 
DUCKDB_API unique_ptr< MultiFileListGlobFileList (const string &path, const FileGlobInput &input=FileGlobOptions::DISALLOW_EMPTY)
 
DUCKDB_API vector< OpenFileInfoGlobFiles (const string &pattern, const FileGlobInput &input=FileGlobOptions::DISALLOW_EMPTY)
 
virtual DUCKDB_API void RegisterSubSystem (unique_ptr< FileSystem > sub_fs)
 registers a sub-file system to handle certain file name prefixes, e.g. http:// etc.
 
virtual DUCKDB_API void RegisterSubSystem (FileCompressionType compression_type, unique_ptr< FileSystem > fs)
 
virtual DUCKDB_API void UnregisterSubSystem (const string &name)
 Unregister a sub-filesystem by name.
 
virtual DUCKDB_API unique_ptr< FileSystemExtractSubSystem (const string &name)
 
virtual DUCKDB_API vector< string > ListSubSystems ()
 List registered sub-filesystems, including builtin ones.
 
virtual DUCKDB_API bool CanHandleFile (const string &fpath)
 Whether or not a sub-system can handle a specific file path.
 
virtual DUCKDB_API void Seek (FileHandle &handle, idx_t location)
 Set the file pointer of a file handle to a specified location. Reads and writes will happen from this location.
 
virtual DUCKDB_API idx_t SeekPosition (FileHandle &handle)
 
virtual DUCKDB_API bool IsManuallySet ()
 If FS was manually set by the user.
 
virtual DUCKDB_API void SetDisabledFileSystems (const vector< string > &names)
 
virtual DUCKDB_API bool SubSystemIsDisabled (const string &name)
 
virtual DUCKDB_API bool IsDisabledForPath (const string &path)
 Check if the filesystem that would handle this path is disabled.
 
virtual DUCKDB_API string CanonicalizePath (const string &path, optional_ptr< FileOpener > opener=nullptr)
 Canonicalize a path.
 
template<class TARGET >
TARGETCast ()
 
template<class TARGET >
const TARGETCast () const
 

Static Public Member Functions

static void VerifyGZIPHeader (uint8_t gzip_hdr[], idx_t read_count, optional_ptr< CompressedFile > source_file)
 Verifies that a buffer contains a valid GZIP header.
 
static bool CheckIsZip (const char *length, idx_t size)
 
static string UncompressGZIPString (const string &in)
 Consumes a byte stream as a gzip string, returning the decompressed string.
 
static string UncompressGZIPString (const char *length, idx_t size)
 
- Static Public Member Functions inherited from duckdb::FileSystem
static DUCKDB_API FileSystemGetFileSystem (ClientContext &context)
 
static DUCKDB_API FileSystemGetFileSystem (DatabaseInstance &db)
 
static DUCKDB_API FileSystemGet (AttachedDatabase &db)
 
static DUCKDB_API void SetWorkingDirectory (const string &path)
 Sets the working directory.
 
static DUCKDB_API string GetWorkingDirectory ()
 Gets the working directory.
 
static DUCKDB_API string GetHomeDirectory (optional_ptr< FileOpener > opener)
 Gets the users home directory.
 
static DUCKDB_API string ExpandPath (const string &path, optional_ptr< FileOpener > opener)
 Expands a given path, including e.g. expanding the home directory of the user.
 
static DUCKDB_API optional_idx GetAvailableMemory ()
 Returns the system-available memory in bytes. Returns DConstants::INVALID_INDEX if the system function fails.
 
static DUCKDB_API optional_idx GetAvailableDiskSpace (const string &path)
 Returns the space available on the disk. Returns DConstants::INVALID_INDEX if the information was not available.
 
static DUCKDB_API string GetEnvVariable (const string &name)
 Returns the value of an environment variable - or the empty string if it is not set.
 
static DUCKDB_API bool HasGlob (const string &str)
 Whether there is a glob in the string.
 
static DUCKDB_API unique_ptr< FileSystemCreateLocal ()
 Create a LocalFileSystem.
 
static DUCKDB_API bool IsRemoteFile (const string &path)
 Whether or not a file is remote or local, based only on file path.
 
static DUCKDB_API bool IsRemoteFile (const string &path, string &extension)
 
static DUCKDB_API bool IsDirectory (const OpenFileInfo &info)
 

Static Private Attributes

static constexpr const idx_t BUFFER_SIZE = 1u << 15
 

Additional Inherited Members

- Protected Member Functions inherited from duckdb::FileSystem
virtual DUCKDB_API unique_ptr< FileHandleOpenFileExtended (const OpenFileInfo &path, FileOpenFlags flags, optional_ptr< FileOpener > opener)
 
virtual DUCKDB_API bool SupportsOpenFileExtended () const
 
virtual DUCKDB_API bool ListFilesExtended (const string &directory, const std::function< void(OpenFileInfo &info)> &callback, optional_ptr< FileOpener > opener)
 
virtual DUCKDB_API bool SupportsListFilesExtended () const
 
virtual DUCKDB_API unique_ptr< MultiFileListGlobFilesExtended (const string &path, const FileGlobInput &input, optional_ptr< FileOpener > opener=nullptr)
 
virtual DUCKDB_API bool SupportsGlobExtended () const
 

Member Function Documentation

◆ OpenCompressedFile()

unique_ptr< FileHandle > duckdb::GZipFileSystem::OpenCompressedFile ( QueryContext  context,
unique_ptr< FileHandle handle,
bool  write 
)
overridevirtual

Reimplemented from duckdb::FileSystem.

77709 {
77710 auto path = handle->path;
77711 return make_uniq<GZipFile>(context, std::move(handle), path, write);
77712}

◆ GetName()

std::string duckdb::GZipFileSystem::GetName ( ) const
inlineoverridevirtual

Return the name of the filesytem. Used for forming diagnosis messages.

Implements duckdb::FileSystem.

75778 {
75779 return "GZipFileSystem";
75780 }

◆ VerifyGZIPHeader()

void duckdb::GZipFileSystem::VerifyGZIPHeader ( uint8_t  gzip_hdr[],
idx_t  read_count,
optional_ptr< CompressedFile source_file 
)
static

Verifies that a buffer contains a valid GZIP header.

77607 {
77608 // include the filename in the error message if known
77609 string file_info = source_file ? ": " + source_file->path : "";
77610
77611 // check for incorrectly formatted files
77612 if (read_count != GZIP_HEADER_MINSIZE) {
77613 throw IOException("Input is not a GZIP stream" + file_info);
77614 }
77615 if (gzip_hdr[0] != 0x1F || gzip_hdr[1] != 0x8B) { // magic header
77616 throw IOException("Input is not a GZIP stream" + file_info);
77617 }
77618 if (gzip_hdr[2] != GZIP_COMPRESSION_DEFLATE) { // compression method
77619 throw IOException("Unsupported GZIP compression method" + file_info);
77620 }
77621 if (gzip_hdr[3] & GZIP_FLAG_UNSUPPORTED) {
77622 throw IOException("Unsupported GZIP archive" + file_info);
77623 }
77624}

◆ CheckIsZip()

bool duckdb::GZipFileSystem::CheckIsZip ( const char length,
duckdb::idx_t  size 
)
static
77626 {
77627 if (size < GZIP_HEADER_MINSIZE) {
77628 return false;
77629 }
77630
77631 auto data_ptr = reinterpret_cast<const uint8_t *>(data);
77632 if (data_ptr[0] != 0x1F || data_ptr[1] != 0x8B) {
77633 return false;
77634 }
77635
77636 if (data_ptr[2] != GZIP_COMPRESSION_DEFLATE) {
77637 return false;
77638 }
77639
77640 return true;
77641}
::uint8_t uint8_t

◆ UncompressGZIPString() [1/2]

string duckdb::GZipFileSystem::UncompressGZIPString ( const string &  in)
static

Consumes a byte stream as a gzip string, returning the decompressed string.

77643 {
77644 return UncompressGZIPString(in.data(), in.size());
77645}
static string UncompressGZIPString(const string &in)
Consumes a byte stream as a gzip string, returning the decompressed string.
Definition duckdb.cpp:77643
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UncompressGZIPString() [2/2]

string duckdb::GZipFileSystem::UncompressGZIPString ( const char length,
idx_t  size 
)
static
77647 {
77648 // decompress file
77649 auto body_ptr = data;
77650
77651 auto mz_stream_ptr = make_uniq<duckdb_miniz::mz_stream>();
77652 memset(mz_stream_ptr.get(), 0, sizeof(duckdb_miniz::mz_stream));
77653
77654 uint8_t gzip_hdr[GZIP_HEADER_MINSIZE];
77655
77656 // check for incorrectly formatted files
77657
77658 // TODO this is mostly the same as gzip_file_system.cpp
77659 if (size < GZIP_HEADER_MINSIZE) {
77660 throw IOException("Input is not a GZIP stream");
77661 }
77662 memcpy(gzip_hdr, body_ptr, GZIP_HEADER_MINSIZE);
77663 body_ptr += GZIP_HEADER_MINSIZE;
77664 GZipFileSystem::VerifyGZIPHeader(gzip_hdr, GZIP_HEADER_MINSIZE, nullptr);
77665
77666 if (gzip_hdr[3] & GZIP_FLAG_EXTRA) {
77667 throw IOException("Extra field in a GZIP stream unsupported");
77668 }
77669
77670 if (gzip_hdr[3] & GZIP_FLAG_NAME) {
77671 char c;
77672 do {
77673 c = *body_ptr;
77674 body_ptr++;
77675 } while (c != '\0' && static_cast<idx_t>(body_ptr - data) < size);
77676 }
77677
77678 // stream is now set to beginning of payload data
77679 auto status = duckdb_miniz::mz_inflateInit2(mz_stream_ptr.get(), -MZ_DEFAULT_WINDOW_BITS);
77680 if (status != duckdb_miniz::MZ_OK) {
77681 throw InternalException("Failed to initialize miniz");
77682 }
77683
77684 auto bytes_remaining = size - NumericCast<idx_t>(body_ptr - data);
77685 mz_stream_ptr->next_in = const_uchar_ptr_cast(body_ptr);
77686 mz_stream_ptr->avail_in = NumericCast<unsigned int>(bytes_remaining);
77687
77688 string decompressed;
77689
77690 while (status == duckdb_miniz::MZ_OK) {
77691 unsigned char decompress_buffer[BUFSIZ];
77692 mz_stream_ptr->next_out = decompress_buffer;
77693 mz_stream_ptr->avail_out = sizeof(decompress_buffer);
77694 status = mz_inflate(mz_stream_ptr.get(), duckdb_miniz::MZ_NO_FLUSH);
77695 if (status != duckdb_miniz::MZ_STREAM_END && status != duckdb_miniz::MZ_OK) {
77696 throw IOException("Failed to uncompress");
77697 }
77698 decompressed.append(char_ptr_cast(decompress_buffer), mz_stream_ptr->total_out - decompressed.size());
77699 }
77700 duckdb_miniz::mz_inflateEnd(mz_stream_ptr.get());
77701
77702 if (decompressed.empty()) {
77703 throw IOException("Failed to uncompress");
77704 }
77705 return decompressed;
77706}
static void VerifyGZIPHeader(uint8_t gzip_hdr[], idx_t read_count, optional_ptr< CompressedFile > source_file)
Verifies that a buffer contains a valid GZIP header.
Definition duckdb.cpp:77607
GOpaque< Size > size(const GMat &src)
Definition duckdb.cpp:76083

◆ CreateStream()

unique_ptr< StreamWrapper > duckdb::GZipFileSystem::CreateStream ( )
overridevirtual

Implements duckdb::CompressedFileSystem.

77714 {
77715 return make_uniq<MiniZStreamWrapper>();
77716}

◆ InBufferSize()

idx_t duckdb::GZipFileSystem::InBufferSize ( )
overridevirtual

Implements duckdb::CompressedFileSystem.

77718 {
77719 return BUFFER_SIZE;
77720}

◆ OutBufferSize()

idx_t duckdb::GZipFileSystem::OutBufferSize ( )
overridevirtual

Implements duckdb::CompressedFileSystem.

77722 {
77723 return BUFFER_SIZE;
77724}

The documentation for this class was generated from the following file: