Skip to content
This repository has been archived by the owner on Mar 16, 2019. It is now read-only.

Commit

Permalink
wip commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wkh237 committed Jul 18, 2016
1 parent ad7f642 commit f612f35
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 23 deletions.
8 changes: 1 addition & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
RNFetchBlobStream
} from './types'
import fs from './fs'
import getUUID from './utils/uuid'
import base64 from 'base-64'
const {
RNFetchBlobSession,
Expand Down Expand Up @@ -286,13 +287,6 @@ class FetchBlobResponse {

}

function getUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
let r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}

export default {
fetch,
base64,
Expand Down
4 changes: 2 additions & 2 deletions src/ios/RNFetchBlob.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -228,7 +228,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
Expand Down
9 changes: 6 additions & 3 deletions src/polyfill/Blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Web API Blob object polyfill.
*/
import fs from '../fs.js'
import getUUID from '../utils/uuid'

export default class Blob {

Expand All @@ -24,8 +25,8 @@ export default class Blob {
}
else if(typeof data === 'string') {
// content from file
if(data.startsWith('RNFetchBlob-file://') {
enode = 'uri'
if(data.startsWith('RNFetchBlob-file://')) {
encode = 'uri'
}
// BASE64 encoded
else {
Expand Down Expand Up @@ -54,11 +55,13 @@ export default class Blob {
* @return {Blob}
*/
slice(start:?number, end:?number, encoding:?string):Blob {
console.log('slice called')
return fs.slice(this.cacheName, getBlobName(), contentType, start, end)
}
/**
* Release the resource of the Blob object.
* @nonstandard
* @return {Promise}
*/
close() {
Expand All @@ -73,5 +76,5 @@ export default class Blob {
* @return {string} Temporary filename
*/
function getBlobName() {

return 'blob-' + getUUID()
}
2 changes: 1 addition & 1 deletion src/polyfill/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Blob from './Blob.js'
export default class File extends Blob {

constructor() {

super()
}

}
15 changes: 15 additions & 0 deletions src/polyfill/XMLHttpRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default class XMLHttpRequest {

constructor(...args) {
console.log('XMLHttpRequest constructor called', args)
}

send(...data) {
console.log('XMLHttpRequest send called', data)
}

abort(...args) {
console.log('XMLHttpRequest abort called', data)
}

}
3 changes: 2 additions & 1 deletion src/polyfill/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Blob from './Blob.js'
import File from './File.js'
import XMLHttpRequest from './XMLHttpRequest.js'

export default {
Blob, File
Blob, File, XMLHttpRequest
}
6 changes: 6 additions & 0 deletions src/utils/uuid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function getUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
let r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
7 changes: 4 additions & 3 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ node -e "var fs=require('fs'); var pkg = JSON.parse(fs.readFileSync('./RNFetchBl

# install module
cd "${TEST_APP_PATH}"
npm install --save "${CWD}/src"
npm install --save firebase
# npm install --save "${CWD}/src"
npm install --save react-native-fetch-blob@0.7.0-dev.1
rnpm link

# copy android assets
cp ./test/assets/ ./RNFetchBlobTest/android/app/src/main/
cd ${CWD}
cp -R ./test/assets/ ./RNFetchBlobTest/android/app/src/main/assets/

# start RN
cd "${TEST_APP_PATH}"
Expand Down
12 changes: 8 additions & 4 deletions test/test-firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import {
} from 'react-native';

const fs = RNFetchBlob.fs
const Blob = RNFetchBlob.polyfill.Blob
window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
window.Blob = Blob

const { Assert, Comparer, Info, prop } = RNTest
const describe = RNTest.config({
group : 'firebase',
Expand Down Expand Up @@ -45,10 +49,10 @@ describe('firebase login', (report, done) => {
console.log('firebase sigin failed', err)
})
firebase.auth().onAuthStateChanged((user) => {
report(<Assert key="login success"
report(<Assert key="login status" uid="100"
expect={user !== undefined}
actual={user}/>,
<Info key="user content">
<Info key="user content" uid="user data">
<Text>{JSON.stringify(user)}</Text>
</Info>)
done()
Expand All @@ -59,9 +63,9 @@ describe('firebase login', (report, done) => {
describe('upload file to firebase', (report, done) => {

try {

let storage = firebase.storage().ref()
let task = storage.file(`testdata/firebase-test-${Platform.OS}.png`).put(webFile, metadata)
let task = storage.child(`testdata/firebase-test-${Platform.OS}.png`).put(new Blob('hello !'), { contentType : 'text/plain' })

task.on('state_change', null, (err) => {

Expand Down
4 changes: 2 additions & 2 deletions test/test-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const { Assert, Comparer, Info, prop } = RNTest
// test environment variables

prop('FILENAME', `${Platform.OS}-0.7.0-${Date.now()}.png`)
prop('TEST_SERVER_URL', 'http://192.168.16.70:8123')
prop('TEST_SERVER_URL_SSL', 'https://192.168.16.70:8124')
prop('TEST_SERVER_URL', 'http://192.168.0.11:8123')
prop('TEST_SERVER_URL_SSL', 'https://192.168.0.11:8124')
prop('DROPBOX_TOKEN', 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4')
prop('styles', {
image : {
Expand Down

0 comments on commit f612f35

Please sign in to comment.