Realm-js: Can not download realm-sync-cocoa

Created on 30 Jan 2018  路  4Comments  路  Source: realm/realm-js

When i run 'react-native run-ios' after run 'yarn add realm'.
I can't download the 'realm-sync-cocoa-2.2.9.tar.gz' file.

Stop in this screen for more then 1 hour. 猬囷笍猬囷笍猬囷笍
2018-01-30 5 30 30

When i ping static.realm.io, i can get the request, although the speed is slow.猬囷笍猬囷笍猬囷笍
2018-01-30 5 34 17

Need some help.

O-Community T-Help

Most helpful comment

@kneth

Finally , I solve the problem.

I find out the file /realm/scripts/download-realm.js 锛宼hen find the code,

function download(serverFolder, archive, destination) {
    const url = `https://static.realm.io/downloads/${serverFolder}/${archive}`;
    console.log('serverFolder',serverFolder);
    console.log('archive',archive);
    console.log('destination',destination)
    console.log(`Download url: ${url}`);
    return fetch(url).then((response) => {
        if (response.status !== 200) {
            throw new Error(`Error downloading ${url} - received status ${response.status} ${response.statusText}`);
        }

        const lastModified = new Date(response.headers.get('Last-Modified'));
        return fs.exists(destination)
                 .then(exists => {
                     if (!exists) {
                         return saveFile();
                     } else {
                         return fs.stat(destination)
                                  .then(stat => {
                                      if (stat.mtime.getTime() !== lastModified.getTime()) {
                                          console.log('stat.mtime',stat.mtime.getTime())
                                          console.log('lastModified',lastModified.getTime())
                                          return saveFile();
                                      }
                         })
                     }
        });

        function saveFile() {
            if (process.stdout.isTTY) {
                printProgress(response.body, parseInt(response.headers.get('Content-Length')), archive);
            } else {
                console.log(`Downloading ${archive}`);
            }
            return new Promise((resolve) => {
                const file = fs.createWriteStream(destination);
                response.body.pipe(file).once('finish', () => file.close(resolve));
            }).then(() => fs.utimes(destination, lastModified, lastModified));
        }
    });
}

I print the archive in the terminal, then found the exact path the file('realm-sync-cocoa') save in.
I replace the file and forbid this code,

 return fs.exists(destination)
                 .then(exists => {
                     if (!exists) {
                         return saveFile();
                     } else {
                         return fs.stat(destination)
                                  .then(stat => {
                                      if (stat.mtime.getTime() !== lastModified.getTime()) {
                                          console.log('stat.mtime',stat.mtime.getTime())
                                          console.log('lastModified',lastModified.getTime())
                                          return saveFile();
                                      }
                         })
                     }
        });

The project work finally.

All 4 comments

@kk412027247 I can download it just fine: curl https://static.realm.io/downloads/sync/realm-sync-cocoa-2.2.9.tar.gz -O

As Realm contains encryption technology, your IP address might be blocked due to export regulations. Moreover, we have seen that some countries block access to Amazon S3 (which is hosting static.realm.io).

@kneth

Finally , I solve the problem.

I find out the file /realm/scripts/download-realm.js 锛宼hen find the code,

function download(serverFolder, archive, destination) {
    const url = `https://static.realm.io/downloads/${serverFolder}/${archive}`;
    console.log('serverFolder',serverFolder);
    console.log('archive',archive);
    console.log('destination',destination)
    console.log(`Download url: ${url}`);
    return fetch(url).then((response) => {
        if (response.status !== 200) {
            throw new Error(`Error downloading ${url} - received status ${response.status} ${response.statusText}`);
        }

        const lastModified = new Date(response.headers.get('Last-Modified'));
        return fs.exists(destination)
                 .then(exists => {
                     if (!exists) {
                         return saveFile();
                     } else {
                         return fs.stat(destination)
                                  .then(stat => {
                                      if (stat.mtime.getTime() !== lastModified.getTime()) {
                                          console.log('stat.mtime',stat.mtime.getTime())
                                          console.log('lastModified',lastModified.getTime())
                                          return saveFile();
                                      }
                         })
                     }
        });

        function saveFile() {
            if (process.stdout.isTTY) {
                printProgress(response.body, parseInt(response.headers.get('Content-Length')), archive);
            } else {
                console.log(`Downloading ${archive}`);
            }
            return new Promise((resolve) => {
                const file = fs.createWriteStream(destination);
                response.body.pipe(file).once('finish', () => file.close(resolve));
            }).then(() => fs.utimes(destination, lastModified, lastModified));
        }
    });
}

I print the archive in the terminal, then found the exact path the file('realm-sync-cocoa') save in.
I replace the file and forbid this code,

 return fs.exists(destination)
                 .then(exists => {
                     if (!exists) {
                         return saveFile();
                     } else {
                         return fs.stat(destination)
                                  .then(stat => {
                                      if (stat.mtime.getTime() !== lastModified.getTime()) {
                                          console.log('stat.mtime',stat.mtime.getTime())
                                          console.log('lastModified',lastModified.getTime())
                                          return saveFile();
                                      }
                         })
                     }
        });

The project work finally.

@kk412027247 You are welcome to contribute any enhancements as a pull request :-)

@kk412027247 You saved my day,
I found The corrupted file in /var/folders/7q/90mfr6bd4k565n7ynbldkxzh0000gn/T/realm-sync-cocoa-3.5.6.tar.gz and replaced it with a better one.
Then editing the file you mentioned solved my problem

Was this page helpful?
0 / 5 - 0 ratings

Related issues

timanglade picture timanglade  路  3Comments

emrehayirci picture emrehayirci  路  3Comments

camslaz picture camslaz  路  4Comments

jmartindivmedianet picture jmartindivmedianet  路  3Comments

blagoev picture blagoev  路  3Comments