Skip to content

Commit 9a7034b

Browse files
authored
Merge pull request #519 from pyro9/truncate
Add truncate method to Adafruit_LittleFS_File.
2 parents b5f5bdd + 85b6e26 commit 9a7034b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

libraries/Adafruit_LittleFS/src/Adafruit_LittleFS_File.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,32 @@ uint32_t File::size (void)
272272
return ret;
273273
}
274274

275+
bool File::truncate (uint32_t pos)
276+
{
277+
int32_t ret=LFS_ERR_ISDIR;
278+
_fs->_lockFS();
279+
if (!this->_is_dir)
280+
{
281+
ret = lfs_file_truncate(_fs->_getFS(), _file, pos);
282+
}
283+
_fs->_unlockFS();
284+
return ( ret == 0 );
285+
}
286+
287+
bool File::truncate (void)
288+
{
289+
int32_t ret=LFS_ERR_ISDIR;
290+
uint32_t pos;
291+
_fs->_lockFS();
292+
if (!this->_is_dir)
293+
{
294+
pos = lfs_file_tell(_fs->_getFS(), _file);
295+
ret = lfs_file_truncate(_fs->_getFS(), _file, pos);
296+
}
297+
_fs->_unlockFS();
298+
return ( ret == 0 );
299+
}
300+
275301
void File::flush (void)
276302
{
277303
_fs->_lockFS();

libraries/Adafruit_LittleFS/src/Adafruit_LittleFS_File.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class File : public Stream
7070
uint32_t position (void);
7171
uint32_t size (void);
7272

73+
bool truncate (uint32_t pos);
74+
bool truncate (void);
75+
7376
void close (void);
7477

7578
operator bool (void);

0 commit comments

Comments
 (0)