-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9fcdf4f
commit 2011431
Showing
7 changed files
with
85 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'dart:math'; | ||
|
||
class RandomService { | ||
static const _chars = | ||
'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890'; | ||
final Random _rnd = Random(); | ||
|
||
String getRandomString(int length) => String.fromCharCodes(Iterable.generate( | ||
length, (_) => _chars.codeUnitAt(_rnd.nextInt(_chars.length)))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import 'dart:io'; | ||
import 'package:archive/archive_io.dart'; | ||
import 'package:odin/services/locator.dart'; | ||
import 'package:odin/services/random_service.dart'; | ||
import 'package:path/path.dart'; | ||
import 'package:path_provider/path_provider.dart'; | ||
|
||
class ZipService { | ||
final RandomService _randomService = locator<RandomService>(); | ||
|
||
Future<File> zipFile({ | ||
required List<File> fileToZips, | ||
}) async { | ||
final ZipFileEncoder encoder = ZipFileEncoder(); | ||
final Directory zipFileSaveDirectory = await getTemporaryDirectory(); | ||
final zipFileSavePath = zipFileSaveDirectory.path; | ||
// Manually create a zip at the zipFilePath | ||
final String zipFilePath = | ||
join(zipFileSavePath, "${_randomService.getRandomString(15)}.zip"); | ||
encoder.create(zipFilePath); | ||
// Add all the files to the zip file | ||
for (final File fileToZip in fileToZips) { | ||
encoder.addFile(fileToZip); | ||
} | ||
encoder.close(); | ||
return File(zipFilePath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters