feat(mongodb): add Compass-style collection import/export

This commit is contained in:
onenewcode authored and GitHub committed 2026-09-12 21:59:29 +08:00
1 parent bf4874906c
commit 8ff56b4837
47 files changed
+5626 -52

No files matched your search

+13 -3
View File
@@ -537,7 +537,7 @@ pub fn csv_value(value: &str) -> serde_json::Value {
const IMPORT_ENCODING_READ_CHUNK_BYTES: usize = 16 * 1024;
// Decodes incrementally and rejects malformed input instead of silently inserting replacement characters.
struct StrictTranscodingReader<R> {
pub(crate) struct StrictTranscodingReader<R> {
reader: R,
decoder: encoding_rs::Decoder,
encoding: TableImportTextEncoding,
@@ -702,7 +702,7 @@ fn auto_detect_text_encoding_from_bytes(bytes: &[u8]) -> Result<(TableImportText
Err("Could not detect text encoding; select UTF-8, GBK / GB18030, or UTF-16 manually".to_string())
}
fn resolve_text_encoding_from_bytes(
pub(crate) fn resolve_text_encoding_from_bytes(
bytes: &[u8],
requested: Option<TableImportTextEncoding>,
) -> Result<(TableImportTextEncoding, usize), String> {
@@ -803,7 +803,7 @@ fn auto_detect_text_encoding_from_file_with_progress(
Err("Could not detect text encoding; select UTF-8, GBK / GB18030, or UTF-16 manually".to_string())
}
fn resolve_text_encoding_from_file_with_progress(
pub(crate) fn resolve_text_encoding_from_file_with_progress(
path: &str,
requested: Option<TableImportTextEncoding>,
on_progress: impl FnMut(u64),
@@ -838,6 +838,16 @@ fn resolve_and_validate_text_encoding_from_file(
Ok((encoding, bom_len))
}
pub(crate) fn open_transcoded_text_file(
path: &str,
encoding: Option<TableImportTextEncoding>,
) -> Result<(StrictTranscodingReader<File>, TableImportTextEncoding), String> {
let (encoding, bom_len) = resolve_text_encoding_from_file_with_progress(path, encoding, |_| {})?;
let mut file = File::open(path).map_err(|error| error.to_string())?;
file.seek(SeekFrom::Start(bom_len as u64)).map_err(|error| error.to_string())?;
Ok((StrictTranscodingReader::new(file, encoding)?, encoding))
}
fn open_delimited_csv_reader_with_progress(
path: &str,
source_format: TableImportSourceFormat,