Giter Site home page Giter Site logo

dw250100785 / ezsync Goto Github PK

View Code? Open in Web Editor NEW
6.0 4.0 13.0 101 KB

cross-platform sync tool for File and Sqlite/ 跨平台数据同步(云存储)客户端,支持文件目录、sqlite,支持IOS、Android、Windows、Linux

Makefile 1.26% C++ 88.43% Java 4.49% Objective-C 0.12% Objective-C++ 0.61% Shell 0.50% C 4.59%

ezsync's Introduction

ezSync

cross-platform sync tool for File and Sqlite

WHAT

ezync 提供简单的方式用于将数据保存到云端服务器,以及在不同设备间同步数据。其特性包括:

  • 支持对文件和目录的同步,更新的最小单位是文件,对文件格式无要求
  • 支持对sqlite数据库的增量更新同步,更新的最小单位是行,要求同步的数据库表必须有PK。能自动处理数据库表升级导致的字段增减问题。
  • 基于版本控制的多设备间同步
  • 严格的原子性控制,防止更新过程中数据损坏
  • 能够检查到版本冲突,并提供途径由上层应用解决冲突
  • 简单的服务端实现,只需实现基本的RESTful接口:GET、POST、PUT、HEAD、MOVE、DELETE
  • 支持IOS、Android、Linux、Windows

典型使用场景:

  • 笔记类应用,如有道笔记等。
  • 配置项下发
  • 客户端日志收集

HOW

C++

//版本冲突处理策略
//冲突时总是使用本地版本
class UseLocal:public IEzsyncMergeStrategy{
public:
    ezsync::UseWitch merge(const std::string& key,const ezsync::Entry&,const ezsync::Entry&){
        std::cout << key << " merged:use_local"<<std::endl;
        return USE_LOCAL;
    }
}_use_local;


std::shared_ptr<IEzsyncClientWrap> client;
std::map<std::string, std::string> map ;
map["local_type"]="file";
map["host"]="xxx.com:443";  //服务器地址
map["local_storage"]="/home/caoym/testfles/"; //需同步的数据的本地地址
map["remote_storage"]="/testfles/"; //需同步的数据的远端地址

map["local_history"]=path.UTF8String; //本地版本信息存放地址
map["remote_history"]=remote.UTF8String; //远端版本信息存放地址
//创建客户端
if(map["local_type"] == "file"){
    client.reset(new EzsyncClientWrap<ezsync::FileSyncClient2>(ezsync::FileSyncClientBuilder2::build(map)));
}else if(map["local_type"] == "sqlite"){
    client.reset(new EzsyncClientWrap<ezsync::SqliteSyncClient2>(ezsync::SqliteSyncClientBuilder2::build(map)));
}
//下载
_client->update(_use_local, "", "", NULL);
//上传
client->commint("");

Android

//用户数据库同步
String user_sqlite_sync = "{\"local_type\":\"sqlite\",\"host\":\"10.94.16.61:8111\",\"encrypt\":\"1\"}";
SQLiteDatabase db =  _db.getReadableDatabase();
String db_path = db.getPath();
db.close();

StorageDesc storage = StorageDesc.createFromJson(user_sqlite_sync);
storage.setLocalStorage(db_path); //本地存储路径
storage.setRemoteStorage("testdb"); // 云端存储路径

Client client = new Client(storage.getConfig());
//下载
client.update(new MergeStrategy() {
		@Override
		public int merge(String key, Entry local, Entry remote) {
			System.out.println(key + " use remote");
			return MergeStrategy.UseRemote;
		}
		
	});
//上传
client.commit();

iOS

SyncClient*client = [[SyncClient alloc] initWithLocal:"xxxx" 
                                              forType:@"file"
                                             withHost:@"127.0.0.1:443" 
                                          withRemote:"/tests"];
//下载
[client update];
//上传
[client commit];

依赖

  • curl
  • boost
  • openssl
  • rapidjson
  • zlib

ezsync's People

Stargazers

Xianliang Ge avatar  avatar  avatar thouen avatar jimmy8854 avatar

Watchers

dengwei avatar jinguangyang avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.