Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit36118c1

Browse files
authored
Merge pull request#3 from coriolinus/prgn/feat/file-set-len
2 parentsf9a69a0 +54a5073 commit36118c1

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

‎src/fs/native/file.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ impl File {
5656
pubasyncfnsync_data(&self) -> io::Result<()>{
5757
self.inner.sync_data().await
5858
}
59+
60+
/// Truncates or extends the underlying file, updating the size of this file to become `size`.
61+
///
62+
/// If `size` is less than the current file's size, then the file will be shrunk. If it is greater
63+
/// than the currrent file's size, then the file will be extended to `size` and have all intermediate
64+
/// data filled with 0s.
65+
///
66+
/// The file's cursor is not changed. In particular, if the cursor was at the end of the file and
67+
/// the file was shrunk using this operation, the cursor will now be past the end.
68+
pubasyncfnset_len(&self,size:u64) -> io::Result<()>{
69+
self.inner.set_len(size).await
70+
}
5971
}
6072

6173
impl futures::io::AsyncReadforFile{

‎src/fs/wasm/file.rs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,30 @@ impl File {
7777
|size|Ok(sizeasu64),
7878
)
7979
}
80+
81+
/// Truncates or extends the underlying file, updating the size of this file to become `size`.
82+
///
83+
/// If `size` is less than the current file's size, then the file will be shrunk. If it is greater
84+
/// than the currrent file's size, then the file will be extended to `size` and have all intermediate
85+
/// data filled with 0s.
86+
///
87+
/// The file's cursor is not changed. In particular, if the cursor was at the end of the file and
88+
/// the file was shrunk using this operation, the cursor will now be past the end.
89+
///
90+
/// If the requested length is greater than 9007199254740991 (max safe integer in a floating-point context),
91+
/// this will produce an error.
92+
pubasyncfnset_len(&self,size:u64) -> io::Result<()>{
93+
constMAX_SAFE_INT:u64 = js_sys::Number::MAX_SAFE_INTEGERas_;
94+
if size >MAX_SAFE_INT{
95+
returnErr(std::io::Error::new(
96+
std::io::ErrorKind::InvalidInput,
97+
format!("requested size {size} too large, max allowed is {MAX_SAFE_INT}"),
98+
));
99+
}
100+
self.sync_access_handle
101+
.truncate_with_f64(sizeas_)
102+
.map_err(|err|OpfsError::from(err).into_io_err())
103+
}
80104
}
81105

82106
implFile{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp