MCPcopy Create free account
hub / github.com/erans/pgsqlite / create_temp_mapped

Method create_temp_mapped

src/protocol/memory_mapped.rs:85–112  ·  view source on GitHub ↗

Create a memory-mapped temporary file

(data: &[u8], config: &MemoryMappedConfig)

Source from the content-addressed store, hash-verified

83
84 /// Create a memory-mapped temporary file
85 fn create_temp_mapped(data: &[u8], config: &MemoryMappedConfig) -> io::Result<Self> {
86 let mut temp_file = if let Some(ref dir) = config.temp_dir {
87 NamedTempFile::new_in(dir)?
88 } else {
89 NamedTempFile::new()?
90 };
91
92 // Write data to temp file
93 temp_file.write_all(data)?;
94 temp_file.flush()?;
95
96 // Memory map the file
97 let file = temp_file.reopen()?;
98 // Safety: This is safe because:
99 // 1. The file is freshly created and written with valid data
100 // 2. memmap2::Mmap::map() handles the OS-level memory mapping safely
101 // 3. The file descriptor remains valid for the lifetime of the mapping
102 let mmap = unsafe { Mmap::map(&file)? };
103
104 debug!("Created memory-mapped value: {} bytes", data.len());
105
106 Ok(MappedValue::Mapped {
107 mmap,
108 offset: 0,
109 length: data.len(),
110 _temp_file: Some(temp_file),
111 })
112 }
113
114 /// Get a slice view of the data
115 pub fn as_slice(&self) -> &[u8] {

Callers

nothing calls this directly

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected