Compare commits
No commits in common. "main" and "0.1.0" have entirely different histories.
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +0,0 @@
|
|||||||
.*.sw?
|
|
||||||
data_uri
|
|
@ -1,6 +1,6 @@
|
|||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "1.0.2"
|
version = "0.1.0"
|
||||||
author = "Jonathan Bernard"
|
author = "Jonathan Bernard"
|
||||||
description = "Utility for managing data-uris: transforming data to and from, etc."
|
description = "Utility for managing data-uris: transforming data to and from, etc."
|
||||||
license = "GPL-3.0-only"
|
license = "GPL-3.0-only"
|
||||||
@ -13,11 +13,8 @@ bin = @["data_uri"]
|
|||||||
|
|
||||||
requires @[
|
requires @[
|
||||||
"nim >= 1.4.4",
|
"nim >= 1.4.4",
|
||||||
"docopt >= 0.6.8",
|
"docopt 0.6.8",
|
||||||
"filetype",
|
"filetype",
|
||||||
"zero_functional",
|
|
||||||
"update-nim-package-version"
|
|
||||||
]
|
|
||||||
|
|
||||||
task updateVersion, "Update the version of this package.":
|
"https://git.jdb-labs.com/jdb/update-nim-package-version"
|
||||||
exec "update_nim_package_version data_uri 'src/data_uripkg/version.nim'"
|
]
|
||||||
|
BIN
src/.data_uri.nim.swp
Normal file
BIN
src/.data_uri.nim.swp
Normal file
Binary file not shown.
@ -1,13 +1,13 @@
|
|||||||
## Data URI Utilities
|
## Data URI Utilities
|
||||||
|
|
||||||
import std/[base64, logging, os, sequtils, strutils, wordwrap]
|
import base64, docopt, filetype, logging, nre, os
|
||||||
import std/nre except toSeq
|
from strutils import isEmptyOrWhitespace
|
||||||
import docopt, filetype, zero_functional
|
|
||||||
|
|
||||||
import data_uripkg/version
|
include "data_uripkg/version.nim"
|
||||||
|
|
||||||
let dataUriPattern = re"^data:([^;,]+)?(;base64)?,(.+)$"
|
let dataUriPattern = re"^data:([^;,]+)?(;base64)?,(.+)$"
|
||||||
|
|
||||||
|
|
||||||
proc encodeAsDataUri*(value: string, mimeType: string = ""): string =
|
proc encodeAsDataUri*(value: string, mimeType: string = ""): string =
|
||||||
let actualMimeType =
|
let actualMimeType =
|
||||||
if mimeType.isEmptyOrWhitespace: filetype.match(cast[seq[byte]](value)).mime.value
|
if mimeType.isEmptyOrWhitespace: filetype.match(cast[seq[byte]](value)).mime.value
|
||||||
@ -48,10 +48,6 @@ Options:
|
|||||||
-t, --type <mimeType> Manually set the MIME type rather than trying to
|
-t, --type <mimeType> Manually set the MIME type rather than trying to
|
||||||
infer it from the file extension. This only applies
|
infer it from the file extension. This only applies
|
||||||
when encoding files to data-uris.
|
when encoding files to data-uris.
|
||||||
|
|
||||||
-s, --split <length> Split the output across multiple lines with a maximum
|
|
||||||
of <length> characters on each line. By default the
|
|
||||||
output is contiguous, all on one line.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
logging.addHandler(newConsoleLogger())
|
logging.addHandler(newConsoleLogger())
|
||||||
@ -77,20 +73,12 @@ Options:
|
|||||||
try:
|
try:
|
||||||
if args["encode"]:
|
if args["encode"]:
|
||||||
let binaryData = readAll(fileIn)
|
let binaryData = readAll(fileIn)
|
||||||
let encodedData = encodeAsDataUri(binaryData)
|
write(fileOut, encodeAsDataUri(binaryData))
|
||||||
if args["--split"]:
|
|
||||||
write(fileOut, encodedData.wrapWords(parseInt($args["--split"])))
|
|
||||||
else: write(fileOut, encodedData)
|
|
||||||
|
|
||||||
if args["decode"]:
|
if args["decode"]:
|
||||||
let dataUri = readAll(fileIn)
|
let dataUri = readAll(fileIn)
|
||||||
let dataToDecode = (dataUri.splitLines.toSeq -->
|
write(fileOut, decodeDataUri(dataUri))
|
||||||
map(it.replace(re"\s+", ""))).
|
|
||||||
join("")
|
|
||||||
let decodedData = decodeDataUri(dataToDecode)
|
|
||||||
write(fileOut, decodedData)
|
|
||||||
|
|
||||||
except: raise getCurrentException()
|
|
||||||
finally:
|
finally:
|
||||||
close(fileIn)
|
close(fileIn)
|
||||||
close(fileOut)
|
close(fileOut)
|
||||||
|
@ -1 +1 @@
|
|||||||
const DATA_URI_VERSION* = "1.0.2"
|
const DATA_URI_VERSION* = "0.1.0"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user