mediasnacks 0.30.0 → 0.30.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -22,7 +22,7 @@ mediasnacks <command> <args>
22
22
  - `avif` Converts images to AVIF
23
23
  - `png` Optimizes PNG images with oxipng
24
24
  - `sqcrop` Square crops images
25
- - `base64` Encodes a file to data URI
25
+ - `base64` Encodes image to data URI
26
26
 
27
27
 
28
28
  - `resize` Resizes videos or images
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mediasnacks",
3
- "version": "0.30.0",
3
+ "version": "0.30.1",
4
4
  "description": "Utilities for optimizing and preparing videos and images",
5
5
  "license": "MIT",
6
6
  "author": "Eric Fortis",
package/src/base64.js CHANGED
@@ -1,20 +1,31 @@
1
+ import { parse } from 'node:path'
1
2
  import { readFileSync } from 'node:fs'
2
3
  import { parseOptions } from './utils/parseOptions.js'
3
- import { mimeFor } from './utils/mimeFor.js'
4
+
4
5
 
5
6
  const HELP = `
6
7
  SYNOPSIS
7
- mediasnacks base64 [--css | --img] file
8
+ mediasnacks base64 [--css | --img] img
8
9
 
9
10
  DESCRIPTION
10
- Encodes a file to data URI.
11
+ Encodes image to data URI
11
12
 
12
13
  EXAMPLES
13
- mediasnacks base64 file
14
- mediasnacks base64 --img file
15
- mediasnacks base64 --css file
14
+ mediasnacks base64 img
15
+ mediasnacks base64 --img img
16
+ mediasnacks base64 --css img
16
17
  `
17
18
 
19
+ const MIMES = {
20
+ avif: 'image/avif',
21
+ gif: 'image/gif',
22
+ jpg: 'image/jpeg',
23
+ jpeg: 'image/jpeg',
24
+ png: 'image/png',
25
+ svg: 'image/svg+xml',
26
+ webp: 'image/webp',
27
+ }
28
+
18
29
  export default async function main() {
19
30
  const { values, files } = await parseOptions(HELP, {
20
31
  css: { type: 'boolean' },
@@ -34,9 +45,9 @@ export default async function main() {
34
45
  console.log(data)
35
46
  }
36
47
 
37
- export async function base64(filePath) {
48
+ export async function base64(file) {
38
49
  return {
39
- data: readFileSync(filePath).toString('base64'),
40
- mime: await mimeFor(filePath)
50
+ data: readFileSync(file).toString('base64'),
51
+ mime: MIMES[parse(file).ext.toLowerCase().replace('.', '')] || 'application/octect'
41
52
  }
42
53
  }
@@ -1,21 +0,0 @@
1
- import { parse } from 'node:path'
2
- import { runSilently } from './subprocess.js'
3
-
4
-
5
- export async function mimeFor(filePath) {
6
- return process.platform === 'win32'
7
- ? await windowsMime(filePath)
8
- : (await runSilently('file', ['--mime-type', '--brief', filePath])).stdout.trim()
9
- }
10
-
11
- async function windowsMime(filePath) { // TODO test on windows
12
- const ext = parse(filePath).ext.toLowerCase()
13
- try {
14
- const { stdout } = await runSilently('reg', ['query', `HKEY_CLASSES_ROOT\\${ext}`, '/v', 'Content Type'])
15
- const match = stdout.match(/Content Type\s+REG_SZ\s+(\S+)/)
16
- if (match)
17
- return match[1]
18
- }
19
- catch {}
20
- return 'application/octet-stream'
21
- }