15 Commits
1 ... master

Author SHA1 Message Date
ac00262e46 readme 2014-11-06 09:46:00 -08:00
2081a41bd2 Merge pull request #3 from ThomasHintz/testing-github-2
Add deprecated message to with-bucket.
2014-07-10 09:34:03 -07:00
Thomas
eb28ee2a96 Add deprecated message to with-bucket. 2014-07-10 09:33:00 -07:00
e2f0e718eb Create LICENSE 2014-02-05 12:35:01 -08:00
0f5aedbf22 Mark with-bucket as deprecated. 2013-09-24 17:47:08 -07:00
thintz
8fbc5a540e Release new version the actually increments the version number. 2013-07-19 10:02:50 -07:00
thintz
887319ad05 Release new version. 2013-07-17 09:34:02 -07:00
7b32156467 Fix put-string! and put-sexp!.
Thanks to Seth Alves for reporting the bug and providing a patch.
2013-07-17 09:07:46 -07:00
f1f2e2a663 version 6 2012-05-04 08:23:13 -07:00
7b26d6acb2 fix a typo 2012-04-28 14:29:29 -07:00
c78a161fa1 added get/put file 2012-04-28 14:25:57 -07:00
3c4ee2cf36 Forgot to update .setup 2011-08-15 20:57:22 -07:00
2419d958eb Added release-info. 2011-08-03 22:00:39 -07:00
1ce89c9c1c Fixed category. 2011-08-02 22:05:47 -07:00
40056295f8 Added chicken-install setup info. 2011-08-02 22:00:19 -07:00
8 changed files with 130 additions and 18 deletions

22
LICENSE Normal file
View File

@@ -0,0 +1,22 @@
Copyright (c) 2011-2013, Thomas Hintz
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

8
README.md Normal file
View File

@@ -0,0 +1,8 @@
chicken-scheme-amazon-s3
========================
Amazon S3 access from Chicken Scheme.
This project has been moved to
https://github.com/sethalves/chicken-scheme-amazon-s3.
Use it instead for submitting patches and pull requests instead.

15
amazon-s3.meta Normal file
View File

@@ -0,0 +1,15 @@
; author: Thomas Hintz
; email: t@thintz.com
; license: bsd
(
(license "BSD")
(category web)
(needs base64 sha1 http-client uri-common intarweb srfi-19 hmac ssax sxpath)
(test-depends test srfi-1)
(author "Thomas Hintz")
(synopsis "Provides an interface to the Amazon S3 service."))

10
amazon-s3.release-info Normal file
View File

@@ -0,0 +1,10 @@
(repo git "git://github.com/ThomasHintz/chicken-scheme-{egg-name}.git") ; optional
(uri targz "https://github.com/ThomasHintz/chicken-scheme-{egg-name}/tarball/{egg-release}")
(release "1")
(release "2")
(release "3")
(release "4")
(release "5")
(release "6")
(release "7")

View File

@@ -11,7 +11,7 @@
;; procs ;; procs
list-objects list-buckets bucket-exists? create-bucket! delete-bucket! get-object put-object! delete-object! list-objects list-buckets bucket-exists? create-bucket! delete-bucket! get-object put-object! delete-object!
put-string! put-sexp! get-string get-sexp put-string! put-sexp! put-file! get-string get-sexp get-file
;; macros ;; macros
with-bucket) with-bucket)
@@ -103,31 +103,65 @@
(bucket #f) (bucket #f)
(path #f) (path #f)
(sxpath '()) (sxpath '())
(body '()) (body "")
(verb "GET") (verb "GET")
(ns '((x . "http://s3.amazonaws.com/doc/2006-03-01/"))) (ns '((x . "http://s3.amazonaws.com/doc/2006-03-01/")))
(no-xml #f) (no-xml #f)
(no-auth #f) (no-auth #f)
(reader-thunk read-string)
(content-type "application/x-www-form-urlencoded") (content-type "application/x-www-form-urlencoded")
(content-length 0)) (content-length 0))
;(handle-exceptions
; exn
; ((condition-property-accessor 'client-error 'body) exn)
(with-input-from-request (with-input-from-request
(aws-request bucket path verb no-auth: no-auth content-type: content-type content-length: content-length) (aws-request bucket path verb no-auth: no-auth content-type: content-type content-length: content-length)
body body
(if no-xml (if no-xml
read-string reader-thunk
(aws-xml-parser sxpath ns)))) (aws-xml-parser sxpath ns))))
(define (read-byte-file path . port)
(lambda ()
(let ((file (open-input-file path)))
(letrec ((read-next
(lambda ()
(let ((b (read-byte file)))
(if (eof-object? b)
#t
(begin
(if (> (length port) 0)
(write-byte b (car port))
(write-byte b))
(read-next)))))))
(read-next))
(close-input-port file))))
(define (write-byte-file path . port)
(lambda ()
(let ((file (open-output-file path)))
(letrec ((read-next
(lambda ()
(let ((b (if (> (length port) 0)
(read-byte (car port))
(read-byte))))
(if (eof-object? b)
#t
(begin
(write-byte b file)
(read-next)))))))
(read-next))
(close-output-port file))))
;;; api ;;; api
; broken and deprecated
; next version will have parameterized keywords so this
; won't be necessary
(define-syntax with-bucket (define-syntax with-bucket
(syntax-rules () (syntax-rules ()
((with-bucket bucket (func p1 ...)) ((with-bucket bucket (func p1 ...))
(func bucket p1 ...)) (func bucket p1 ...))
((with-bucket bucket exp body ...) ((with-bucket bucket exp body ...)
(begin (with-bucket bucket exp) (begin (print "I am deprecated.")
(with-bucket bucket exp)
(with-bucket bucket body ...))))) (with-bucket bucket body ...)))))
(define (list-buckets) (define (list-buckets)
@@ -150,16 +184,19 @@
(perform-aws-request bucket: bucket sxpath: '(x:ListBucketResult x:Contents x:Key *text*))) (perform-aws-request bucket: bucket sxpath: '(x:ListBucketResult x:Contents x:Key *text*)))
(define (put-object! bucket key object-thunk object-length object-type) (define (put-object! bucket key object-thunk object-length object-type)
(perform-aws-request bucket: bucket path: key verb: "PUT" content-type: object-type body: (object-thunk) (perform-aws-request bucket: bucket path: key verb: "PUT" content-type: object-type body: object-thunk
content-length: object-length no-xml: #t)) content-length: object-length no-xml: #t))
(define (put-string! bucket key string) (define (put-string! bucket key string)
(put-object! bucket key (lambda () string) (string-length string) "text/plain")) (put-object! bucket key (lambda () (display string)) (string-length string) "text/plain"))
(define (put-sexp! bucket key sexp) (define (put-sexp! bucket key sexp)
(let-values (((res request-uri response) (put-string! bucket key (->string sexp)))) (let-values (((res request-uri response) (put-string! bucket key (->string sexp))))
(values res request-uri response))) (values res request-uri response)))
(define (put-file! bucket key file-path)
(put-object! bucket key (read-byte-file file-path) (file-size file-path) "binary/octet-stream"))
(define (get-object bucket key) (define (get-object bucket key)
(perform-aws-request bucket: bucket path: key no-xml: #t)) (perform-aws-request bucket: bucket path: key no-xml: #t))
@@ -170,6 +207,9 @@
(let-values (((string request-uri response) (get-string bucket key))) (let-values (((string request-uri response) (get-string bucket key)))
(values (call-with-input-string string read) request-uri response))) (values (call-with-input-string string read) request-uri response)))
(define (get-file bucket key file-path)
(perform-aws-request bucket: bucket path: key no-xml: #t reader-thunk: (write-byte-file file-path)))
(define (delete-object! bucket key) (define (delete-object! bucket key)
(perform-aws-request bucket: bucket path: key no-xml: #t verb: "DELETE")) (perform-aws-request bucket: bucket path: key no-xml: #t verb: "DELETE"))

15
amazon-s3.setup Normal file
View File

@@ -0,0 +1,15 @@
; author: Thomas Hintz
; email: t@thintz.com
; license: bsd
(compile -s -O2 -d1 amazon-s3.scm -j amazon-s3)
(compile -s amazon-s3.import.scm -O2 -d0)
(compile -c -O2 -d1 amazon-s3.scm -unit amazon-s3 -j amazon-s3)
(install-extension
'amazon-s3
; Files to install for your extension:
'("amazon-s3.o" "amazon-s3.so" "amazon-s3.import.so")
; Assoc list with properties for your extension:
'((version 7)
(static "amazon-s3.o"))) ;; for static linking

1
tests/file Normal file
View File

@@ -0,0 +1 @@
eat good food

View File

@@ -2,10 +2,7 @@
; email: t@thintz.com ; email: t@thintz.com
; license: bsd ; license: bsd
(load "amazon-s3.scm") (use test srfi-1 amazon-s3)
(use test srfi-1)
(use amazon-s3)
(define *b* "chicken-scheme-test-bucket") (define *b* "chicken-scheme-test-bucket")
@@ -23,6 +20,10 @@
(test-assert "Delete Object 2" (delete-object! *b* "string")) (test-assert "Delete Object 2" (delete-object! *b* "string"))
(test-assert "Put Sexp" (put-sexp! *b* "sexp" '(+ 1 2 3))) (test-assert "Put Sexp" (put-sexp! *b* "sexp" '(+ 1 2 3)))
(test "Get Sexp" 6 (eval (get-sexp *b* "sexp"))) (test "Get Sexp" 6 (eval (get-sexp *b* "sexp")))
(test-assert "Put File" (put-file! *b* "file" "test-in-file"))
(test-assert "Get File" (get-file *b* "file" "test-out-file"))
(test "Get/Put File 1" #t (string=? (with-input-from-file "test-in-file" (lambda () (read-string)))
(with-input-from-file "test-out-file" (lambda () (read-string)))))
(test-assert "Delete Object 3" (delete-object! *b* "sexp")) (test-assert "Delete Object 3" (delete-object! *b* "sexp"))
(test-assert "Delete Bucket" (delete-bucket! *b*))) (test-assert "Delete Bucket" (delete-bucket! *b*)))