Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
arnoudbuzing committed Aug 6, 2018
1 parent 33ab67f commit 6f15da0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
40 changes: 40 additions & 0 deletions Prototypes/Files.wl
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,43 @@ If[ $SystemID === "Windows-x86-64",
$LocalAppDataDirectory = FileNameJoin[{$AppDataDirectory, "Local"}];
$RoamingAppDataDirectory = FileNameJoin[{$AppDataDirectory, "Roaming"}];
]


FilePartition[file_String, size_] :=
Module[{n, dir, filesize, count, in, uuid, partdir, out, bytes, done},
count =
If[IntegerQ[size], size,
QuantityMagnitude[UnitConvert[size, "Bytes"]]];
dir = DirectoryName[file];
in = OpenRead[file, BinaryFormat -> True];
uuid = CreateUUID[];
partdir = CreateDirectory[FileNameJoin[{dir, uuid}]];
i = 0;
While[Length[bytes = BinaryReadList[in, "Byte", count]] > 0,
out = OpenWrite[
FileNameJoin[{partdir,
"part-" <> IntegerString[(i++), 10, 16] <> ".data"}],
BinaryFormat -> True];
BinaryWrite[out, bytes, "Byte"];
];
Close[out];
Close[in];
partdir
]

FileJoin[partdir_String, name_String] :=
Module[{parts, dir, file, out, in, bytes},
parts = Sort[FileNames["part-*.data", partdir]];
dir = DirectoryName[partdir];
file = FileNameJoin[{dir, name}];
out = OpenWrite[file, BinaryFormat -> True];
Map[
Function[{f},
in = OpenRead[f, BinaryFormat -> True];
bytes = BinaryReadList[in, "Byte"];
BinaryWrite[out, bytes, "Byte"];
Close[in];
], parts];
Close[out];
file
]
4 changes: 2 additions & 2 deletions Prototypes/PacletInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Description -> "A paclet for prototype functions",
Creator -> "Arnoud Buzing",
Publisher -> "Wolfram Research",
Version -> "0.3.0",
Version -> "0.3.1",
MathematicaVersion -> "11.2+",
Loading -> Automatic,
Thumbnail -> "icons/icon.png",
Expand Down Expand Up @@ -56,7 +56,7 @@
"Prototypes`$RoamingAppDataDirectory",
"Prototypes`$UUIDStringPattern", "Prototypes`LayeredGeoGraphics",
"Prototypes`RenderOnlineNotebook","Prototypes`CreateNotebookRenderAPI",
"Prototypes`CaptureFromIPCamera","Prototypes`Prototype"},
"Prototypes`CaptureFromIPCamera","Prototypes`Prototype", "Prototypes`FilePartition", "Prototypes`FileJoin"},
Context -> {"Prototypes`"} }
}
]
2 changes: 2 additions & 0 deletions Prototypes/Usage.wl
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,5 @@ CreateNotebookRenderAPI::usage = "CreateNotebookRenderAPI[] creates the cloud ap
RenderOnlineNotebook::usage = "RenderOnlineNotebook[url] reads 'url' and opens a private editable copy";
(* prototype *)
Prototype::usage = "Prototype[\"symbol\"] modifies System 'symbol' in a custom way. The modified behavior is printed to the session"
FilePartition::usage = "FilePartition[file,size] partitions 'file' into chunks with the given 'size' and places them in a new directory"
FileJoin::usage = "FileJoin[dir,file] combines binary part files in 'dir' into a single 'file'"

0 comments on commit 6f15da0

Please sign in to comment.