Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New :std/mime/types #1105

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ module.exports = {
'xml',
'parser',
'values',
'mime/',

{ title: "Networking Libraries",
path: "/reference/std/net/",
Expand Down
6 changes: 5 additions & 1 deletion doc/build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/usr/bin/env bash


cd ${0%/*}


emacs ../src/std/mime/README.org --batch -f org-gfm-export-to-markdown --kill ||
echo "Cannot export from org to markdown using emacs"


npm install
NODE_OPTIONS=--openssl-legacy-provider npm run build
106 changes: 106 additions & 0 deletions doc/reference/std/mime/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Media (AKA MIME) types

There's often a need to know content types.

Email can contain other documents of varying types. The Web can serve files of any kind. Email extensions evolved into "Media Types".

::: tip To use bindings from this module

`(import :std/mime/types)`

:::


## `path-extension->mime-type-name`

```scheme
(path-extension->mime-type-name path) => string or #f

path := a filename
```

The [`define-mime-types`](#define-mime-types) database has a [`mime-extensions`](#mime-extensions) map the get a [`mime-type`](#mime-type) from an extension via [`extension->mime-type`](#extension-mime-type). This procedure unites them.

```scheme
> (path-extension->mime-type-name "foo.ss")
"text/x-scheme.gerbil"
> (path-extension->mime-type-name "around-the-world.mp3")
"audio/mpeg"
> (path-extension->mime-type-name "Urgent: Outlook mail!.msg")
"application/vnd.ms-outlook"
```


<a id="extension-mime-type"></a>

## `extension->mime-type`

```scheme
(extension->mime-type str) => mime-type or #f
```


<a id="mime-extensions"></a>

## `mime-extensions`

```scheme
(def mime-extensions (make-hash-table))
```

A map of extensions to `mime-type`'s.


## `mime-types`

```scheme
(def mime-types (make-hash-table))
```

A map of names to `mime-types`


## `add-mime-type`

```scheme
(add-mime-type name ext ...) => mime-type
```

Add a newly created `mime=type` to the `mime-types` and `mime-extensions` mapping.


## `make-mime-type`

```scheme
(make-mime-type name ext ...) => mime-type
```


<a id="mime-type"></a>

## `mime-type`

```scheme
(defstruct mime-type (name extensions) transparent: #t constructor: :init!)
```


<a id="define-mime-types"></a>

## `define-mime-types`

```scheme
(define-mime-types
file-or-definition ...)

file := A path tp a file like `/etc/mime.types`
definition := ("type/name" "ext" ...)
```

```scheme
(define-mime-types
"./mime.types"
("text/x-scheme" "scm" "sps" "sls" "sld")
("text/x-scheme.gerbil" "ss")
("application/vnd.ms-outlook" "msg"))
```
12 changes: 8 additions & 4 deletions src/std/build-spec.ss
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@
"srfi/160/c64"
"srfi/160/c128"
"srfi/212"
;; :std/mime
"mime/struct"
(gxc: "mime/types" (extra-inputs: ("mime/mime.types")))
;; :std/parser
"parser/rlang"
"parser/base"
Expand Down Expand Up @@ -207,10 +210,11 @@
,(cond-expand
(darwin
`(gxc: "net/ssl/libssl"
"-ld-options" ,(append-options
(ldflags "libssl" "-lssl")
(ldflags "libcrypto" "-lcrypto")
(string-append "-L" (gerbil-libdir)) "-lgambit")))
"-cc-options" ,(cppflags "libssl" "")
"-ld-options" ,(append-options
(ldflags "libssl" "-lssl")
(ldflags "libcrypto" "-lcrypto")
(string-append "-L" (gerbil-libdir)) "-lgambit")))
(else `(gxc: "net/ssl/libssl"
"-ld-options" ,(ldflags "libssl" "-lssl"))))
"net/ssl/error"
Expand Down
150 changes: 150 additions & 0 deletions src/std/mime/README.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#+TITLE: Media types and Multipurpose Internet Mail Extensions
#+EXPORT_FILE_NAME: ../../../doc/reference/std/mime/README.md
#+OPTIONS: toc:nil

* Contents :noexport:
:PROPERTIES:
:TOC: :include siblings :depth 3 :ignore (this)
:END:

:CONTENTS:
- [[#media-aka-mime-types][Media (AKA MIME) types]]
- [[#path-extension-mime-type-name][path-extension->mime-type-name]]
- [[#extension-mime-type][extension->mime-type]]
- [[#mime-extensions][mime-extensions]]
- [[#mime-types][mime-types]]
- [[#add-mime-type][add-mime-type]]
- [[#make-mime-type][make-mime-type]]
- [[#mime-type][mime-type]]
- [[#define-mime-types][define-mime-types]]
:END:


* Media (AKA MIME) types
:PROPERTIES:
:CUSTOM_ID: media-aka-mime-types
:END:

There's often a need to know content types.

Email can contain other documents of varying types. The Web can serve
files of any kind. Email extensions evolved into "Media Types".


::: tip To use bindings from this module

~(import :std/mime/types)~

:::


** =path-extension->mime-type-name=
:PROPERTIES:
:CUSTOM_ID: path-extension-mime-type-name
:END:

#+begin_src scheme
(path-extension->mime-type-name path) => string or #f

path := a filename
#+end_src

The [[#define-mime-types][=define-mime-types=]] database has a [[#mime-extensions][=mime-extensions=]] map the get a
[[#mime-type][=mime-type=]] from an extension via [[#extension-mime-type][=extension->mime-type=]]. This
procedure unites them.

#+begin_src scheme
> (path-extension->mime-type-name "foo.ss")
"text/x-scheme.gerbil"
> (path-extension->mime-type-name "around-the-world.mp3")
"audio/mpeg"
> (path-extension->mime-type-name "Urgent: Outlook mail!.msg")
"application/vnd.ms-outlook"
#+end_src


** =extension->mime-type=
:PROPERTIES:
:CUSTOM_ID: extension-mime-type
:END:

#+begin_src scheme
(extension->mime-type str) => mime-type or #f
#+end_src

** =mime-extensions=
:PROPERTIES:
:CUSTOM_ID: mime-extensions
:END:

#+begin_src scheme
(def mime-extensions (make-hash-table))
#+end_src

A map of extensions to =mime-type='s.
** =mime-types=
:PROPERTIES:
:CUSTOM_ID: mime-types
:END:

#+begin_src scheme
(def mime-types (make-hash-table))
#+end_src

A map of names to =mime-types=

** =add-mime-type=
:PROPERTIES:
:CUSTOM_ID: add-mime-type
:END:

#+begin_src scheme
(add-mime-type name ext ...) => mime-type
#+end_src

Add a newly created =mime=type= to the =mime-types= and
=mime-extensions= mapping.


** =make-mime-type=
:PROPERTIES:
:CUSTOM_ID: make-mime-type
:END:

#+begin_src scheme
(make-mime-type name ext ...) => mime-type
#+end_src


** =mime-type=
:PROPERTIES:
:CUSTOM_ID: mime-type
:END:


#+begin_src scheme
(defstruct mime-type (name extensions) transparent: #t constructor: :init!)
#+end_src

** =define-mime-types=
:PROPERTIES:
:CUSTOM_ID: define-mime-types
:END:

#+begin_src scheme
(define-mime-types
file-or-definition ...)

file := A path tp a file like `/etc/mime.types`
definition := ("type/name" "ext" ...)
#+end_src

#+begin_src scheme
(define-mime-types
"./mime.types"
("text/x-scheme" "scm" "sps" "sls" "sld")
("text/x-scheme.gerbil" "ss")
("application/vnd.ms-outlook" "msg"))
#+end_src


Loading
Loading