diff --git a/Prototypes/Files.wl b/Prototypes/Files.wl index 855ac6f..75ff45b 100644 --- a/Prototypes/Files.wl +++ b/Prototypes/Files.wl @@ -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 + ] diff --git a/Prototypes/PacletInfo.m b/Prototypes/PacletInfo.m index 781fb78..8c3d050 100644 --- a/Prototypes/PacletInfo.m +++ b/Prototypes/PacletInfo.m @@ -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", @@ -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`"} } } ] diff --git a/Prototypes/Usage.wl b/Prototypes/Usage.wl index 4967f23..20214f4 100644 --- a/Prototypes/Usage.wl +++ b/Prototypes/Usage.wl @@ -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'"